<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :page="page"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
      >
        <template slot="menuLeft">
          <el-button type="primary" @click="back()">返回</el-button>
        </template>
        <template slot="menu" permissionList slot-scope="scope">
          <el-button type="text" size="small" icon="el-icon-view" @click="taskTjCk(scope.row, scope.index)">查看明细 </el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import {getPackageList} from '@/api/h5';
import {tableOption} from '@/const/crud/admin/h5Package';
import {mapGetters} from 'vuex';

export default {
  name: 'wmscorepackage',
  data() {
    return {
      searchForm: {},
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption
    };
  },
  computed: {
    ...mapGetters(['permissions']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.admin_wmtask_add, false),
        delBtn: this.vaildData(this.permissions.admin_wmtask_del, false),
        editBtn: this.vaildData(this.permissions.admin_wmtask_edit, false)
      };
    }
  },
  methods: {
    getList(page, params) {
      if (undefined == this.$route.query.id) {
        this.$message.error('积分包名称不能为空');
        return false;
      }
      this.searchForm.id = this.$route.query.id;
      this.tableLoading = true;
      getPackageList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm
        )
      )
        .then(response => {
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    searchChange(form, done) {
      this.searchForm = form;
      this.page.currentPage = 1;
      this.getList(this.page, form);
      done();
    },
    refreshChange() {
      this.getList(this.page);
    },
    taskTjCk(row, index) {
      window.location.href = '/#/h5/indexTask?id=' + row.id + '&userId=' + row.userId;
    },
    back() {
      window.location.href = '/#/h5';
    }
  }
};
</script>
