<template>
  <basic-container>
    <!-- 槽液检查任务 -->
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @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="handleMaintain">批量维护</el-button>
        <el-button type="primary" @click="handleAudit">批量审核</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" @click="auditRow(scope.row)" v-if="scope.row.auditStatus == 0">审核</el-button>
      </template>
    </avue-crud>
    <!-- 批量 审核-->
    <auditBatchDialog
      v-if="showAudit"
      :showAudit="showAudit"
      :auditData="auditData"
      @closeDialog="closeDialog"
    ></auditBatchDialog>

    <!-- 批量 维护-->
    <maintainBathDialog
      :show-maintain="showMaintain"
      :maintain-data="maintainData"
      @closeDialog="closeDialog"
    ></maintainBathDialog>
  </basic-container>

  <!-- 单个审核 -->
  <auditDialog
    v-if="showSingleAudit"
    :showDialog="showSingleAudit"
    :auditData="auditData"
    @closeDialog="closeDialog"
  ></auditDialog>
  <!-- 单个 维护 -->
  <maintainDialog
    v-if="showSingleMaintain"
    :showDialog="showSingleMaintain"
    :maintain-data="maintainData"
    @closeDialog="closeDialog"
  ></maintainDialog>
</template>

<script>
import auditBatchDialog from './components/auditBatchDialog.vue';
import maintainBathDialog from './components/maintainBathDialog.vue';

import auditDialog from './components/auditDialog.vue';
import maintainDialog from './components/maintainDialog.vue';
import { getList } from '@/api/processManagement/bathRefineTask.js';
export default {
  components: {
    auditBatchDialog,
    maintainBathDialog,
    auditDialog,
    maintainDialog,
  },
  data() {
    return {
      showSingleAudit: false,
      showSingleMaintain: false,
      showAudit: false,
      showMaintain: false,
      loading: false,
      auditData: [],
      maintainData: [],

      auditStatus: '',
      auditDescribe: '',
      data: [],
      form: {},

      selectionList: [],
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        height: 'auto',
        calcHeight: 32,
        tip: false,
        rowKey: 'id',
        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: 80,
        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: 'wcId',
            type: 'select',
            filterable:true,
            clearable: true,
            width: 200,
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            searchLabelWidth: 80,
            rules: [
              {
                required: true,
                message: '请输入作业中心',
                trigger: 'blur',
              },
            ],
            dicUrl: '/blade-desk/bsWorkCenter/getList',
            props: {
              label: 'wcName',
              value: 'id',
            },
          },
          {
            label: '作业槽/设备检查项',
            prop: 'batchNo',
            type: 'select',
            filterable:true,
            clearable: true,
            search: false,
            width: 200,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            rules: [
              {
                required: true,
                message: '请输入槽名槽号/设备检查项',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '维护内容',
            prop: 'accumulateRelevantInfo',
            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: 'taskCreateTime',
            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: 'finishManStr',
            width: 120,
            type: 'select',
            filterable:true,
            clearable: true,
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            rules: [
              {
                required: true,
                message: '请输入责任人',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '维护时间',
            prop: 'finishManStr',
            width: 120,
            type: 'select',
            filterable:true,
            clearable: true,
            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: 'isQualified',
            search: false,
            width: 120,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchMenuPosition: 'right',
            type: 'select',
            filterable:true,
            clearable: true,
            dicData: [
              {
                label: '合格',
                value: 1,
              },
              {
                label: '不合格',
                value: 0,
              },
            ],
            rules: [
              {
                required: true,
                message: '请输入是否合格',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '状态',
            prop: 'taskStatus',
            type: 'select',
            filterable:true,
            clearable: true,
            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: 'auditMan',
            width: 120,
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 60,
            rules: [
              {
                required: true,
                message: '请输入审核人',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '审核时间',
            prop: 'auditTime',
            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;
      this.showSingleAudit = false;
      this.showSingleMaintain = false;
      this.onLoad(this.page);
    },
    selectionChange(val) {
      this.selectionList = val;
    },
    // 单个审批
    auditRow(row) {
      this.auditData = [];
      this.auditData.push(row);
      this.showSingleAudit = true;
    },
    // 批量审核
    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 = [];
      this.maintainData.push(row);
      this.showSingleMaintain = 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.maintainData = this.selectionList;
      this.showMaintain = true;
    },
    selectionClear() {},
    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>
