<template>
  <div>
    <!-- 定期类检查项配置 -->

    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
       @row-update="rowUpdate"
    >
      <template #menu-left>
        <el-button type="primary" @click="handleAdd">新增</el-button>
      </template>

      <template #menu="scope">
        <!-- <el-button type="text" @click="editRow(scope.row)">修改</el-button>
        <el-button type="text" @click="rowDel(scope.row)">删除</el-button> -->
      </template>
    </avue-crud>

    <!-- 新增 -->
    <addPeriodicalClass
      v-if="showDialog"
      :showDialog="showDialog"
      :moldAddMore="moldAddMore"
      :tabPosition="tabPosition"
      @closeDialog="closeDialog"
    ></addPeriodicalClass>
  </div>
</template>

<script>
import { getList, add, remove, update } from '@/api/processManagement/planClass.js';

import addPeriodicalClass from './addPeriodicalClassDialog.vue';
// bbpType: 3 --槽液检查 4 --设备检查
export default {
  components: { addPeriodicalClass },
  data() {
    return {
      moldAddMore: false,
      tabPosition: 'bathInspection',
      loading: false,
      title: '新增',
      tableData: [],
      showDialog: false,
      data: [],
      form: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },


      option: {
        height: 'auto',
        align: 'center',
        calcHeight: 32,
        rowKey: 'twlId',
        tip: false,
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        viewBtn: false,
        delBtn: true,
        addBtn: false,
        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',
        column: [
        {
            label: '作业中心',
            prop: 'wcId',
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            searchLabelWidth: 80,
            dicUrl: '/blade-desk/bsWorkCenter/getList',
            type:'select',
            props: {
                label: 'wcName',
                value: 'id',
            },
            rules: [
                {
                    required: true,
                    message: '请输入作业中心',
                    trigger: 'blur',
                },
            ],
        },
        {
            label: '作业槽',
            prop: 'batchNo',
            type: 'select',
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 80,
            rules: [
                {
                    required: true,
                    message: '请输入作业槽',
                    trigger: 'blur',
                },
            ],
            dicData: [
                { label: "#21", value: '1' },
                { label: "11", value: '11' },
                { label: "#22", value: '3' },
            ]
        },
        {
            label: '维护内容',
            prop: 'preserveContent',
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            searchLabelWidth: 80,
            rules: [
                {
                    required: true,
                    message: '请输入维护内容',
                    trigger: 'blur',
                },
            ],
        },

        {
            label: '审批状态',
            prop: 'approvalStatus',
            type: 'select',
            search: false,
            hide: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 80,
            display: false,
            rules: [
                {
                    required: true,
                    message: '请输入审批状态',
                    trigger: 'blur',
                },
            ],
            dicData: [
                {
                    value: -1,
                    label: '发送审批'
                }, {
                    value: 0,
                    label: '审批中'
                }, {
                    value: 1,
                    label: '审批完毕'
                }
            ]
        },
        {
            label: '维护人',
            prop: 'craftName',
            search: false,
            sortable: true,
            headerAlign: 'center',
            align: 'center',
            display: false,
        },
        {
            label: '维护时间',
            prop: 'craftName',
            search: false,
            sortable: true,
            headerAlign: 'center',
            align: 'center',
            display: false,
        }
    ],
      },
    };
  },
  mounted() {
  },
  methods: {
    closeDialog() {
      this.showDialog = false;
    },
    selectChange(list, row) {
      row._select = !row._select;
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },
     rowUpdate(row, index, done, loading) {
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        error => {
          window.console.log(error);
          loading();
        }
      );
    },
    insertEvent() {
      const record = { bsWorkCenter: { wcId: '' }, _select: false };
      this.tableData.push(record);
    },
    editRow(row) {
      this.tableData = [];
      this.tableData.push(row);
      this.title = '修改';
      this.showDialog = true;
    },
    handleSave() {
      this.showDialog = false;
    },
    deleteRow(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {});
    },
    handleAdd() {
      this.title = '新增';
      this.tableData = [];
      this.showDialog = true;
      this.moldAddMore = 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, { bbpType: 3 })
      ).then(res => {
        this.data = res.data.data.records;
        this.loading = false;
        this.page.total = res.data.data.total;
      });
    },
  },
};
</script>

<style></style>
