<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"
      @row-del="rowDel"
    >
      <template #menu="scope">
        <el-button type="text" v-if="scope.row.approvalStatus == -1">审批</el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>
<script>
import { getList, add, remove, update } from '@/api/processManagement/planClass.js';
export default {
  data() {
    return {
      loading: false,
      data: [],
      form: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        height: 'auto',
        calcHeight: 32,
        rowKey: 'twlId',
        tip: false,
        size: 'medium',
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        viewBtn: false,
        delBtn: true,
        addBtn: true,
        editBtn: true,
        editBtnText: '修改',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        viewBtnText: '详情',
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 220,
        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',
            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',
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 80,
            dicData: [
                { label: "#21", value: '1' },
                { label: "11", value: '11' },
                { label: "#22", value: '3' },
            ],
            rules: [
              {
                required: true,
                message: '请输入作业槽',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '维护内容',
            prop: 'preserveContent',
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            searchLabelWidth: 80,
            rules: [
              {
                required: true,
                message: '请输入维护内容',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '安排日期',
            prop: 'arrangeTime',
            type: 'date',
            searchRange: true,
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 80,
            format: 'YYYY-MM-DD HH:mm:ss',
            valueFormat: 'YYYY-MM-DD HH:mm:ss',
            rules: [
              {
                required: true,
                message: '请输入安排日期',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '审批状态',
            prop: 'approvalStatus',
            type: 'select',
            addDisplay: false,
            editDisplay: false,
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 80,
            searchOrder: 20,
            dicData: [
              {
                value: -1,
                label: '发送审批',
              },
              {
                value: 0,
                label: '审批中',
              },
              {
                value: 1,
                label: '审批完毕',
              },
            ],
            rules: [
              {
                required: true,
                message: '请输入审批状态',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '维护人',
            prop: 'keepManStr',
            search: false,
            sortable: true,
            headerAlign: 'center',
            align: 'center',
            display: false,
          },
          {
            label: '维护时间',
            prop: 'keepTime',
            search: false,
            sortable: true,
            headerAlign: 'center',
            align: 'center',
            display: false,
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(res => {
         remove(row.id).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '删除成功!',
          });
          done();
        });
      });
    },
    rowSave(row, done, loading) {
      add({...row, bbpType: 1}).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        error => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowUpdate(row, index, done, loading) {
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        error => {
          window.console.log(error);
          loading();
        }
      );
    },
    searchReset() {
      this.query = {bbpType: 1};
      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,{bbpType: 1})).then(res => {
        this.data = res.data.data.records;
        this.loading = false;
        this.page.total = res.data.data.total;
        this.selectionClear();
      });
    },
  },
};
</script>
