<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #menu-left>
        <el-button type="primary" @click="addDialog()">新增</el-button>
      </template>
      <template #menu-right> </template>
      <template #menu="{ row }">
        <el-button type="text" @click="detailsDialog(row)">详情</el-button>
        <el-button
          type="text"
          @click="updateDialog(row)"
          v-if="row.arr10 == '3' || row.arr10 == '4' || row.arr10 == '5'"
          >修改</el-button
        >
        <el-button
          type="text"
          @click="review(row)"
          v-if="row.arr10 == '1' || row.arr10 == '2' || row.arr10 == '0'"
          >审核</el-button
        >
      </template>
    </avue-crud>

    <!-- 新增 -->
    <addDialog
      v-if="infoShow"
      :showDialog="infoShow"
      @closeDialog="closeDialog"
      :infoTitle="infoTitle"
    ></addDialog>

    <!-- 审核 -->
    <checkDialog
      v-if="checkResultOpen"
      @closeDialog="closeDialog"
      :show-dialog="checkResultOpen"
      :rowItem="rowItem"
    ></checkDialog>

    <!-- 详情 -->
    <detailsDialog
      v-if="detailsOpen"
      :showDialog="detailsOpen"
      @closeDialog="closeDialog"
      :rowItem="rowItem"
    ></detailsDialog>
  </basic-container>
</template>

<script>
import addDialog from './components/addDialog.vue';
import checkDialog from './components/checkDialog.vue';
import detailsDialog from './components/detailsDialog.vue';
export default {
  components: {
    addDialog,
    checkDialog,
    detailsDialog,
  },
  data() {
    return {
      checkResultOpen: false,
      detailsOpen: false,
      infoShow: false,
      infoTitle: '新增',
      form: {},
      selectionList: [],
      query: {},
      loading: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        columnSort: true,
        tip: false,
        height: 'auto',
        calcHeight: 32,
        simplePage: false,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        editBtnText: '修改',
        labelWidth: 120,
        menuWidth: 100,
        dialogWidth: 900,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        excelBtn: true,
        showOverflowTooltip: true,
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        gridBtn: false,
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: 'left',
        gridBtn: false,
        searchMenuPosition: 'right',
        align: 'center',
        column: [
          {
            label: '提出人',
            prop: 'arr1',
            search: true,
            sortable: true,
            span: 12,
          },
          {
            label: '岗位',
            prop: 'arr2',
            search: true,
            sortable: true,
            span: 12,
          },
          {
            label: '发生时间',
            prop: 'arr3',
            search: true,
            sortable: true,
            span: 12,
          },
          {
            label: '免责问题描述',
            prop: 'arr4',
            search: true,
            sortable: true,
            span: 12,
          },
          {
            label: '原因',
            prop: 'arr5',
            search: true,
            sortable: true,
            span: 12,
          },
          {
            label: '措施',
            prop: 'arr6',
            search: true,
            sortable: true,
            span: 12,
          },
          {
            label: '免责理由',
            prop: 'arr7',
            search: true,
            sortable: true,
            span: 12,
          },
          {
            label: '免责金额',
            prop: 'arr8',
            search: true,
            sortable: true,
            span: 12,
          },
          // {
          //   label: '固化文件',
          //   prop: 'arr9',
          //   search: true,
          //   sortable: true,
          //   span: 12,
          // },
          {
            label: '状态',
            prop: 'arr10',
            search: true,
            sortable: true,
            span: 12,
            type: 'select',
            dicData: [
              {
                label: '待工艺员审批',
                value: 0,
              },
              {
                label: '待质量工程师审批',
                value: 1,
              },
              {
                label: '待业务主管审批',
                value: 2,
              },
              {
                label: '工艺员驳回',
                value: 3,
              },
              {
                label: '质量工程师退回',
                value: 4,
              },
              {
                label: '业务主管审批',
                value: 5,
              },
            ],
          },
        ],
      },

      data: [],
      rowItem: {},
    };
  },
  methods: {
    // 详情
    detailsDialog(row) {
      this.detailsOpen = true;
      this.rowItem = row;
    },
    // 审核
    review(row) {
      this.checkResultOpen = true;
      this.rowItem = row;
    },
    // 新增
    addDialog() {
      this.infoShow = true;
      this.infoTitle = '新增';
    },
    // 修改
    updateDialog() {
      this.infoShow = true;
      this.infoTitle = '修改';
    },
    // 关闭
    closeDialog() {
      this.infoShow = false;
      this.detailsOpen = false;
      this.onLoad(this.page, this.query);
    },
    rowSave(row, done, loading) {
      // addPersonAbility(row).then(
      //   () => {
      //     this.onLoad(this.page);
      //     this.$message({
      //       type: 'success',
      //       message: '操作成功!',
      //     });
      //     done();
      //   },
      //   error => {
      //     window.console.log(error);
      //     loading();
      //   }
      // );
    },
    rowUpdate(row, index, done, loading) {
      // updatePersonAbility(row).then(
      //   () => {
      //     this.onLoad(this.page);
      //     this.$message({
      //       type: 'success',
      //       message: '操作成功!',
      //     });
      //     done();
      //   },
      //   error => {
      //     window.console.log(error);
      //     loading();
      //   }
      // );
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          // return removePersonAbility(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },

    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },

    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    handleChange(file, fileList) {
      // proxy.$Export.xlsx(file.raw).then((data) => {
      //     data.value = data.results;
      // });
      this.$message({
        type: 'success',
        message: '操作成功!',
      });
    },

    onLoad(page, params = {}) {
      this.data = [
        {
          arr1: '张三',
          arr2: '热表分厂',
          arr3: '2026-01-09',
          arr4: '问题描述1',
          arr5: '正常操作',
          arr6: '下次注意',
          arr7: '正常损耗',
          arr8: '55',
          arr10: 0,
        },
        {
          arr1: '张三',
          arr2: '热表分厂',
          arr3: '2026-01-09',
          arr4: '问题描述1',
          arr5: '正常操作',
          arr6: '下次注意',
          arr7: '正常损耗',
          arr8: '55',
          arr10: '1',
        },
        {
          arr1: '张三',
          arr2: '热表分厂',
          arr3: '2026-01-09',
          arr4: '问题描述1',
          arr5: '正常操作',
          arr6: '下次注意',
          arr7: '正常损耗',
          arr8: '55',
          arr10: '2',
        },
        {
          arr1: '张三',
          arr2: '热表分厂',
          arr3: '2026-01-09',
          arr4: '问题描述1',
          arr5: '正常操作',
          arr6: '下次注意',
          arr7: '正常损耗',
          arr8: '55',
          arr10: '3',
        },
        {
          arr1: '张三',
          arr2: '热表分厂',
          arr3: '2026-01-09',
          arr4: '问题描述1',
          arr5: '正常操作',
          arr6: '下次注意',
          arr7: '正常损耗',
          arr8: '55',
          arr10: '4',
        },
        {
          arr1: '张三',
          arr2: '热表分厂',
          arr3: '2026-01-09',
          arr4: '问题描述1',
          arr5: '正常操作',
          arr6: '下次注意',
          arr7: '正常损耗',
          arr8: '55',
          arr10: '5',
        },
      ];
      // this.loading = true;
      // getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
      //   this.data = res.data.data.records;
      //   this.loading = false;
      //   this.page.total = res.data.data.total;
      //   this.selectionClear();
      // });
    },
  },
  mounted() {},
};
</script>
d