<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #menu-left>
        <el-button type="primary" @click="addFn">新增</el-button>
      </template>
      <template #menu="scope">
        <el-button type="text" @click="updateFn(scope.row)">修改</el-button>
      </template>
      <template #bsWorkType.wtName="scope">
        <span>
          {{ scope.row.bsWorkType ? scope.row.bsWorkType.wtName : '-' }}
        </span>
      </template>
      <template #name="{ row }">
        <i :class="row.source" style="margin-right: 5px" />
        <span>{{ row.name }}</span>
      </template>
      <template #source="{ row }">
        <div style="text-align: center">
          <i :class="row.source" />
        </div>
      </template>
    </avue-crud>

    <addTemplateDialog
      v-if="isTemplateOpen"
      :showDialog="isTemplateOpen"
      @closeDialog="closeDialog"
      :moldAddMore="moldAddMore"
      :updateRow="updateRow"
      :title="title"
    >
    </addTemplateDialog>
  </basic-container>
</template>
<script>
import { getList, remove, add, getProcessesTeams } from '@/api/processManagement/processTemplate';
import addTemplateDialog from './components/addTemplateDialog.vue';


export default {
  components: {
    addTemplateDialog,
  },
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      selectionList: [],
      parentId: '',
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        height: 'auto',
        calcHeight: 32,
        tip: false,
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        viewBtn: false,
        addBtn: false,
        editBtn: false,
        delBtn: true,
        editBtnText: '修改',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        viewBtnText: '详情',
        labelWidth: 120,
        menuWidth: 180,
        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: 'code',
            search: false,
            sortable: true,
            overHidden: true,
            width: 120,
            headerAlign: 'center',
            align: 'left',
          },
          {
            label: '模板名称',
            prop: 'name',
            sortable: true,
            search: true,
            width: 120,
            headerAlign: 'center',
            align: 'left',
          },
          {
            label: '模板类型',
            prop: 'templateType',
            sortable: true,
            search: true,
            width: 120,
            headerAlign: 'center',
            align: 'left',
            type: 'select',
            dicUrl: '/blade-system/dict/dictionary?code=processTemplateType',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
          },
          {
            label: '作业中心',
            prop: 'workCenterId',
            sortable: true,
            search: true,
            width: 120,
            headerAlign: 'center',
            align: 'left',
            type: 'select',
            dicUrl: '/blade-desk/bsWorkCenter/getList',
            props: {
              label: 'wcName',
              value: 'id',
            },
          },
          {
            label: '镀种分类',
            prop: 'platingTypeStr',
            sortable: true,
            search: true,
            width: 120,
            headerAlign: 'center',
            align: 'center',
            type: 'select',
            dicUrl: '/blade-desk/bsPlatingType/getPlatingType?current=1&&size=99999',
            props: {
              label: 'plateType',
              value: 'id',
              // res: 'data.records'
            },
          },
          {
            label: '优先级',
            prop: 'priority',
            sortable: true,
            search: false,
            width: 120,
            headerAlign: 'center',
            align: 'center',
          },
          {
            label: '工序数',
            prop: 'processNum',
            sortable: true,
            search: false,
            width: 120,
            headerAlign: 'center',
            align: 'center',
          },
          {
            label: '修改人',
            prop: 'updateUser',
            sortable: true,
            search: false,
            width: 120,
            headerAlign: 'center',
            align: 'center',
          },
          {
            label: '修改时间',
            prop: 'updateTime',
            sortable: true,
            search: false,
            width: 120,
            display: false,
            headerAlign: 'center',
            align: 'center',
          },
          {
            label: '状态',
            prop: 'status',
            sortable: true,
            search: true,
            headerAlign: 'center',
            align: 'center',
            type: 'select',
            searchOrder: 20,
            dicData: [
              {
                label: '正常',
                value: 1,
              },
              {
                label: '异常',
                value: 2,
              },
            ],
            searchValue: 1,
          },
          {
            label: '备注',
            prop: 'memo',
            sortable: true,
            search: false,
            width: 120,
            headerAlign: 'center',
            align: 'left',
          },
        ],
      },
      data: [],
      isTemplateOpen: false,
      moldAddMore: false,
      updateRow: {},
      title:'新增'
      
    };
  },

  methods: {
   
    addFn() {
      this.isTemplateOpen = true;
      this.moldAddMore = true;
      this.title = '新增';
    },
    updateFn(row) {
      this.isTemplateOpen = true;
      this.moldAddMore = true;
      this.updateRow = row;
      this.title = '修改';
    },
    closeDialog() {
      this.isTemplateOpen = false;
      this.onLoad(this.page);
    },
    rowDel(row, index, done) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          // 数据回调进行刷新
          done(row);
        });
    },
    // 重置
    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 = this.data.length;
      });
    },
  },
};
</script>
