<template>
  <basic-container>
    <!-- 槽液检查任务 -->
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @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="handleAudit">批量审核</el-button>
        <el-button type="success" @click="handleMaintain">批量维护</el-button>
      </template>

      <template #menu="scope">
        <el-button type="text" v-if="scope.row.auditStatus == -1" @click="maintainRow(scope.row)"
          >维护</el-button
        >
        <el-button type="text" v-if="scope.row.auditStatus == 0" @click="auditRow(scope.row)"
          >审核</el-button
        >
      </template>
    </avue-crud>
    <audit-dialog
      :show-audit="showAudit"
      :audit-Data="auditData"
      @closeDialog="closeDialog"
    ></audit-dialog>
    <maintain-dialog
      :show-maintain="showMaintain"
      :maintain-data="maintainData"
      @closeDialog="closeDialog"
    ></maintain-dialog>
  </basic-container>
</template>

<script>
import auditDialog from './components/auditDialog.vue';
import maintainDialog from './components/maintainDialog.vue';
import { getList } from '@/api/processManagement/bathRefineTask.js';
export default {
  components: {
    auditDialog,
    maintainDialog,
  },
  data() {
    return {
      loading: false,
      auditData: [],
      maintainData: [],
      showMaintain: false,
      auditStatus: '',
      auditDescribe: '',
      data: [],
      form: {},
      showAudit: false,
      selectionList: [],
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        height: 'auto',
        calcHeight: 32,
        tip: false,
        rowKey: 'keyValue',
        size: 'medium',
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: false,
        selection: true,
        viewBtn: false,
        delBtn: false,
        addBtn: false,
        editBtn: false,
        editBtnText: '修改',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        viewBtnText: '详情',
        labelWidth: 120,
        searchLabelWidth: 150,
        menu: true,
        menuWidth: 100,
        dialogWidth: 1200,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        columnSort: true,
        excelBtn: true,
        columnSort: true,
        showOverflowTooltip: true,
        menuAlign: 'left',
        gridBtn: false,
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        searchMenuPosition: 'right',
        align: 'center',
        column: [
          {
            label: '作业中心',
            prop: 'wcName',
            type: 'select',
            bind: 'dsBatchPreservePlan.bsWorkCenter.wcName',
            width: 200,
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            searchLabelWidth: 80,
            rules: [
              {
                required: true,
                message: '请输入作业中心',
                trigger: 'blur',
              },
            ],
            props: {
              label: 'wcName',
              value: 'wcId',
            },
            dicData: [
              {
                area: 13000.0,
                batchNo: null,
                bigBatch: false,
                checkout: false,
                craftAbility: '化学镀镍',
                createTime: '2023-02-06 12:31:36',
                deleted: false,
                describe: null,
                endPoint: null,
                keyValue: 81,
                limitType: 0,
                processes: '上挂、下挂、交检、化学镀镍、喷砂',
                quantity: null,
                roundCycle: null,
                saturation: 85.0,
                sign: '4',
                startPoint: null,
                team: '化学镀镍一班崔胜伟、化学镀镍一班郭家梁',
                updateTime: '2023-03-06 18:42:47',
                wcCode: '001',
                wcId: 81,
                wcName: '化学镀镍作业中心',
                whetherPlate: false,
              },
              {
                area: 0.0,
                batchNo: null,
                bigBatch: false,
                checkout: false,
                craftAbility: '镀后接收',
                createTime: '2023-02-06 12:48:41',
                deleted: false,
                describe: null,
                endPoint: null,
                keyValue: 85,
                limitType: 0,
                processes: '镀后接收',
                quantity: null,
                roundCycle: null,
                saturation: null,
                sign: '4',
                startPoint: null,
                team: '零件管理班',
                updateTime: '2023-03-06 18:23:20',
                wcCode: '004',
                wcId: 85,
                wcName: '镀后库作业中心',
                whetherPlate: true,
              },
            ],
          },
          {
            label: '作业槽/设备检查项',
            prop: 'batchNo',
            type: 'select',
            bind: 'dsBatchPreservePlan.batchNo',
            search: true,
            width: 200,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            rules: [
              {
                required: true,
                message: '请输入槽名槽号/设备检查项',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '维护内容',
            prop: 'preserveContent',
            bind: 'dsBatchPreservePlan.preserveContent',
            search: true,
            width: 120,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            searchLabelWidth: 80,
            rules: [
              {
                required: true,
                message: '请输入维护内容',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '累计相关信息',
            prop: 'preserveContent',
            width: 150,
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            rules: [
              {
                required: true,
                message: '请输入累计相关信息',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '安排日期',
            prop: 'createTime',
            width: 120,
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 80,
            type: 'date',
            searchRange: true,
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
            rules: [
              {
                required: true,
                message: '请输入安排日期',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '责任人',
            prop: 'userName',
            bind: 'finishMan.userName',
            width: 120,
            type: 'select',
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            rules: [
              {
                required: true,
                message: '请输入责任人',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '实测值/添加量',
            prop: 'actualValue',
            width: 150,
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            rules: [
              {
                required: true,
                message: '请输入实测值/添加量',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '是否合格',
            prop: 'qualifiedTitle',
            search: false,
            width: 120,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchMenuPosition: 'right',
            rules: [
              {
                required: true,
                message: '请输入是否合格',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '状态',
            prop: 'auditStatus',
            type: 'select',
            width: 120,
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 50,
            searchOrder: 20,
            rules: [
              {
                required: true,
                message: '请输入状态',
                trigger: 'blur',
              },
            ],
            dicData: [
              {
                value: -1,
                label: '待维护',
              },
              {
                value: 0,
                label: '待审核',
              },
              {
                value: 1,
                label: '审核通过',
              },
              {
                value: 2,
                label: '审核未通过',
              },
              {
                value: 3,
                label: '过期未维护',
              },
            ],
          },
          {
            label: '审核人',
            prop: 'userName',
            bind: 'auditMan.userName',
            width: 120,
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 60,
            rules: [
              {
                required: true,
                message: '请输入审核人',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '审核时间',
            prop: 'userName',
            bind: 'auditMan.userName',
            width: 120,
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            type: 'date',
            searchRange: true,
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
            rules: [
              {
                required: true,
                message: '请输入审核人',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '审核评价',
            prop: 'auditDescribe',
            search: false,
            sortable: true,
            width: 120,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            rules: [
              {
                required: true,
                message: '请输入审核评价',
                trigger: 'blur',
              },
            ],
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    // 关闭弹窗
    closeDialog() {
      this.showAudit = false;
      this.showMaintain = false;
    },
    selectionChange(val) {
      this.selectionList = val;
    },
    handleAudit() {
      if (this.selectionList.length == 0) {
        this.$message.error('请先选择数据');
        return;
      }
      let tmp = this.selectionList.find(item => item.auditStatus != 0);
      if (tmp) {
        this.$message.error('请选择状态为待审核的数据');
        return;
      }
      this.auditData = this.selectionList;
      this.showAudit = true;
    },
    maintainRow(row) {
      this.maintainData = [];
      row.bsWorkCenter = {
        wcName: row.dsBatchPreservePlan.bsWorkCenter.wcName,
      };
      row.batchNo = row.dsBatchPreservePlan.batchNo;
      row.preserveContent = row.dsBatchPreservePlan.preserveContent;
      this.maintainData.push(row);
      this.showMaintain = true;
    },
    auditRow(row) {
      this.auditData = [];
      this.auditData.push(row);
      this.showAudit = true;
    },
    handleMaintain() {
      if (this.selectionList.length == 0) {
        this.$message.error('请先选择数据');
        return;
      }
      let tmp = this.selectionList.find(item => item.auditStatus != -1);
      if (tmp) {
        this.$message.error('请选择状态为待维护的数据');
        return;
      }
      this.selectionList.map(item => {
        item.bsWorkCenter = {
          wcName: item.dsBatchPreservePlan.bsWorkCenter.wcName,
        };
        item.batchNo = item.dsBatchPreservePlan.batchNo;
        item.preserveContent = item.dsBatchPreservePlan.preserveContent;
      });
      this.maintainData = this.selectionList;
      this.showMaintain = true;
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      // this.query = params;
      // this.page.currentPage = 1;
      // this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      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();
      });
    },
  },
};
</script>

<style></style>
