<template>
  <template-page
    ref="pageRef"
    :get-list="getList"
    :exportList="exportList"
    :table-attributes="tableAttributes"
    :table-events="tableEvents"
    :options-evens-group="optionsEvensGroup"
    :moreParameters="moreParameters"
    :column-parsing="columnParsing"
    :operation="operation()"
  >
    <div slot="moreSearch">
      <el-radio-group v-model="status" size="mini" @change="changeType">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button label="WAIT"
          >待审核({{ goodsApplyCountData.dsh }})</el-radio-button
        >
        <el-radio-button label="OK">通过</el-radio-button>
        <el-radio-button label="FAIL">驳回</el-radio-button>
      </el-radio-group>
      <br /><br />
    </div>
  </template-page>
</template>

<script>
import TemplatePage from "@/components/template/template-page-1.vue";
import import_mixin from "@/components/template/import_mixin.js";
import operation_mixin from "@/components/template/operation_mixin.js";
import {
  goodsApplyList,
  goodsApplyListExport,
  goodsApplyAdd,
  goodsApplyUpdate,
  goodsApplyDetail,
  goodsApplyCount,
} from "@/api/priceAdjustment.js";
import ImageUpload from "@/components/file-upload";
export default {
  components: { TemplatePage, ImageUpload },
  mixins: [import_mixin, operation_mixin],
  data() {
    return {
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: false,
      },
      // 表格事件
      tableEvents: {
        "selection-change": this.selectionChange,
      },
      // 勾选选中行
      recordSelected: [],
      formData: {},
      status: "",
      goodsApplyCountData: {},
    };
  },
  computed: {
    // 事件组合
    optionsEvensGroup() {
      return [
        [
          [
            this.optionsEvensAuth("add", {
              click: () => {
                this.$router.push({
                  path: "/goods/priceAdjustment_children/auditPage",
                  query: {
                    optionType: "add",
                  },
                });
              },
            }),
          ],
        ],
      ];
    },
    // 更多参数
    moreParameters() {
      return [];
    },
  },
  methods: {
    changeType(val) {
      this.$refs?.pageRef?.refreshList();
    },
    // 列表请求函数
    getList(p, cb) {
      try {
        var pam = JSON.parse(JSON.stringify(p));
        pam.params.push({
          param: "a.status",
          compare: "=",
          value: this.status,
        });
        cb && cb(pam);
        return goodsApplyList(pam);
      } catch (error) {
        console.log(error);
      } finally {
        goodsApplyCount().then((res) => {
          this.goodsApplyCountData = res.data;
        });
      }
    },
    // 列表导出函数
    exportList: goodsApplyListExport,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData;
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data;
    },
    // 操作按钮
    operation() {
      return this.operationBtn({
        edit: {
          conditions: ({ row, index, column }) => {
            return ["FAIL", "OK"].includes(row.status);
          },
          click: ({ row, index, column }) => {
            this.$router.push({
              path: "/goods/priceAdjustment_children/auditPage",
              query: {
                goodsApplyId: row.goodsApplyId,
                optionType: "edit",
              },
            });
          },
        },
        details: {
          conditions: ({ row, index, column }) => {
            return true;
          },
          click: ({ row, index, column }) => {
            this.$router.push({
              path: "/goods/priceAdjustment_children/auditPage",
              query: {
                goodsApplyId: row.goodsApplyId,
                optionType: "details",
              },
            });
          },
        },
        examine: {
          conditions: ({ row, index, column }) => {
            return row.status === "WAIT";
          },
          click: ({ row, index, column }) => {
            this.$router.push({
              path: "/goods/priceAdjustment_children/auditPage",
              query: {
                goodsApplyId: row.goodsApplyId,
                optionType: "examine",
              },
            });
          },
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
