<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"
      @row-del="rowDel"
      @rowSave="rowSave"
      @rowUpdate="rowUpdate"
    >
    </avue-crud>
  </basic-container>
</template>
<script>
import { getList, add, remove, update } from '@/api/processManagement/workCenterDevice.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: 18,
        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: 100,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 120,
        dialogWidth: 450,
        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',
        span:24,
        column: [
          {
            label: '作业中心',
            prop: 'wcId',
            type: 'select',
            filterable: true,
            clearable: true,
            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: 'craftManName',
            type: 'select',
            filterable: true,
            clearable: true,
             span:24,
            // multiple: true,
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            dicUrl: '/blade-system/user/page?current=1&&size=99999',
            props: {
              label: 'realName',
              value: 'id',
              res: 'data.records',
            },
            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(res => {
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          this.onLoad(this.page);
          done();
        });
      });
    },
    rowSave(row, done, loading) {
      add(row).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 = {};
      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>
