<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"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #menu-left>
        <el-button @click="setBathCrew()" type="primary">批量分派</el-button>
      </template>

      <template #menu-right="{ size }"> </template>
      <template #menu="scope">
        <el-button type="primary" link @click="setCrew(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>
    <!-- 分派人员弹框 -->
    <assignDaialog
      :id="bcId"
      :set-crew-open="setCrewOpen"
      v-if="setCrewOpen"
      type="platingAssort"
      @setCrewOpeSancel="setCrewOpeSancel"
      :title="title"
      :updateRow="updateRow"
    ></assignDaialog>
  </basic-container>
</template>
<script>
import { getList, setDispatch } from '@/api/processManagement/taskDispatch';
import assignDaialog from './components/assignDaialog.vue';
export default {
  components: {
    assignDaialog,
  },
  data() {
    return {
      bcId: null,
      setCrewOpen: false,
      form: {},
      query: {},
      loading: true,
      selectionList: [],
      parentId: '',
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        height: 'auto',
        calcHeight: 32,
        tip: false,
        size: 'medium',
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 12,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: true,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        addBtn: false,
        editBtnText: '修改',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        viewBtnText: '详情',
        labelWidth: 120,
        menuWidth: 80,
        dialogWidth: 1200,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        columnSort: true,
        excelBtn: true,
        columnSort: true,
        index: false,
        showOverflowTooltip: true,
        menuAlign: 'left',
        gridBtn: false,
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        searchMenuPosition: 'right',
        align: 'center',
        column: [
          {
            label: '零件号',
            prop: 'partCode',
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 60,
          },
          {
            label: '零件名称',
            prop: 'partName',
            sortable: true,
            search: false,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            rules: [
              {
                required: false,
                message: '请选择镀种分类',
                trigger: 'click',
              },
            ],
          },
          {
            label: '任务类型',
            prop: 'taskType',
            sortable: true,
            search: true,
            overHidden: true,
            type: 'select',
            filterable: true,
            clearable: true,
            headerAlign: 'center',
            align: 'center',
            dicUrl: '/blade-system/dict/dictionary?code=processTaskType',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
          },
          {
            label: 'PDM发布时间',
            prop: 'pdmCreateTime',
            sortable: true,
            search: false,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
          },
          {
            label: 'PDM工艺路线',
            prop: 'pdmWay',
            sortable: true,
            search: false,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
          },
          {
            label: '工艺路线详情',
            prop: 'wayDetails',
            sortable: true,
            search: false,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
          },
          {
            label: '在制品建议',
            prop: 'wipTake',
            sortable: true,
            search: false,
            overHidden: true,

            headerAlign: 'center',
            align: 'center',
          },
          {
            label: '备注',
            prop: 'remarks',
            sortable: true,
            search: false,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
          },
        ],
      },
      data: [],
      title: '分派',
      updateRow: [],
    };
  },

  methods: {
    setBathCrew() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.updateRow = this.selectionList;
      this.setCrewOpen = true;
      this.title = '批量分派';
    },
    // 设置班组人员
    setCrew(row) {
      this.updateRow = [row];
      this.setCrewOpen = true;
      this.title = '分派';
    },
    // 设置班组人员弹框关闭
    setCrewOpeSancel(isRefresh) {
      // if (isRefresh) {
      //     this.$refs.myTable.load();
      // }
      this.setCrewOpen = false;
      this.onLoad(this.page);
    },
    // 重置
    searchReset() {
      this.query = {};
      this.parentId = 0;
      this.onLoad(this.page);
    },
    // 搜索
    searchChange(params, done) {
      this.query = params;
      this.parentId = '';
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    // 选中表格数据
    selectionChange(list) {
      this.selectionList = list;
    },
    //
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },

    // 切换 页码
    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;
        this.selectionClear();
      });
    },
  },
};
</script>
