<template>
  <basic-container>
    <avue-crud
      ref="crud"
      :page.sync="page"
      :data="tableData"
      :table-loading="tableLoading"
      :option="tableOption"
      @on-load="getList"
      @refresh-change="refreshChange"
      @size-change="sizeChange"
      @current-change="currentChange"
    >
      <!-- 左侧添加按钮 -->
      <template slot="menuLeft" v-if="userInfo.roles.includes(4)">
        <el-button type="primary" size="small" @click="createFn">新增知会 </el-button>
      </template>
      <!-- 操作栏 -->
      <template slot="menu" slot-scope="scope">
        <el-button v-if="userInfo.roles.includes(41) && scope.row.checkState === 'CKT2'" type="text" size="small" icon="el-icon-reading" @click="reviewFn(scope.row)"
          >审核
        </el-button>
        <el-button type="text" size="small" icon="el-icon-reading" @click="detailFn(scope.row)">查看 </el-button>
      </template>
    </avue-crud>
    <createDialig ref="createDialigRef" @success="refreshChange" />
  </basic-container>
</template>

<script>
import createDialig from './components/createDialig.vue';
import {redemptionNoticePageApi, redemptionNoticeReadApi} from '@/api/distributeVoucher.js';
import {tableOption} from '@/const/crud/distributeVoucher.js';
import {mapGetters} from 'vuex';
export default {
  components: {createDialig},
  data() {
    return {
      tableLoading: false,
      tableOption: tableOption,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableData: []
    };
  },

  computed: {
    ...mapGetters(['userInfo', 'roles'])
  },
  methods: {
    async getList(page, params) {
      this.tableLoading = true;
      const obj = Object.assign(
        {
          current: page.currentPage,
          size: page.pageSize
        },
        params
      );
      const res = await redemptionNoticePageApi(obj);
      if (res.data.code === 0) {
        this.tableData = res.data.data.records;
        this.page.total = res.data.data.total;
      }
      this.tableLoading = false;
    },

    createFn() {
      this.$refs.createDialigRef.show('1');
    },
    detailFn(row) {
      let type;
      if (this.userInfo.roles.includes(37)) {
        type = 3;
      } else {
        type = 2;
      }

      this.$refs.createDialigRef.detail(row, type);
    },
    reviewFn(row) {
      this.$refs.createDialigRef.review(row, 4);
    },
    refreshChange() {
      this.getList(this.page);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-input-number {
  input {
    text-align: left;
  }
}
</style>
