<template>
  <basic-container>
    <div>
      <Card class="cardTitle">
        <p>
          <el-button
            type="primary"
            @click="backPage"
            style="margin-top: 5px; width: 80px"
            >返回</el-button
          >
        </p>
      </Card>
      <avue-crud
        :data="tableDataTask"
        :option="option"
        :page.sync="page"
        :table-loading="tableLoadingTask"
        @on-load="getListTask"
        @size-change="sizeChange"
        @current-change="currentChange"
      >
        <template slot="menu" slot-scope="scope">
          <el-button
            type="text"
            size="small"
            icon="el-icon-tickets"
            @click="showTaskInfo(scope.row, scope.index)"
            >服务详情
          </el-button>
        </template>
      </avue-crud>
    </div>
  </basic-container>
</template>

<script>
import { missionLookdata } from "@/const/crud/missionCenter";
import { fetchSubList } from "@/api/taskManagement/missionCenter";
import Config from "@/settings";
export default {
  name: "approval",
  data() {
    return {
      tableDataTask: [],
      option: missionLookdata,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoadingTask: false,
      searchFormTask: {}
    };
  },
  mounted() {},
  methods: {
    // 返回按钮
    backPage() {
      this.$router.$avueRouter.closeTag();
      this.$router.push({ path: "/admin/taskManagement/missionCenter" });
    },
    // 初始化请求接口
    getListTask(page, params) {
      this.tableLoadingTask = true;
      this.searchFormTask.scorePackageId = this.$route.query.packageId;
      fetchSubList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchFormTask
        )
      )
        .then(response => {
          this.tableDataTask = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoadingTask = false;
        })
        .catch(() => {
          this.tableLoadingTask = false;
        });
    },
    // 条数发生改变
    sizeChange(row) {
      this.page.pageSize = row;
    },
    // 页数发生改变
    currentChange(row) {
      this.page.currentPage = row;
    },
    // 任务详情
    showTaskInfo(row, index) {
      window.open(
        Config.outsideUrl + "/h5/#/pages/task/task-detail/index?id=" + row.id,
        "newwindow",
        "height=500, width=400, top=200, left=300, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
      );
    }
  }
};
</script>

<style>
.cardTitle {
  margin-bottom: 20px;
}
</style>
