<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"
      @row-save="rowSave"
    >
      <template #menu-left>
        <el-button type="primary" @click="addFn">新增</el-button>
      </template>
      <template #menu="scope">
        <el-button type="text" @click="detailsFn(scope.row)"> 详情</el-button>
        <!--    是否展示 -->
        <el-button
          type="text"
          v-if="scope.row.isSpecial == 1"
          @click="setCrew(scope.row)"
        >
          设置班组</el-button
        >
      </template>
      <template #menu-right="{ size }">
        <span style="display: inline-flex; margin-right: 12px">
          <el-button type="primary">导入</el-button>
        </span>
      </template>
      <template #isDispatch="scope">
        <el-tag v-if="scope.row.isDispatch == 1" type="success">是</el-tag>
        <el-tag v-else type="danger">否</el-tag>
      </template>
      <template #isSpecial="scope">
        <el-tag v-if="scope.row.isSpecial == 1" type="success">是</el-tag>
        <el-tag v-else type="danger">否</el-tag>
      </template>
      <template #special="scope">
        <el-tag v-if="scope.row.mainProcess == 1" type="success">是</el-tag>
        <el-tag v-else type="danger">否</el-tag>
      </template>
      <template #isMain="scope">
        <el-tag v-if="scope.row.isMain == 1" type="success">是</el-tag>
        <el-tag v-else type="danger">否</el-tag>
      </template>
      <template #cyropactorControl-label="{ type, disabled }">
        <span></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>

    <setCrew
      :pId="rowId"
      :set-crew-open="setCrewOpen"
      v-if="setCrewOpen"
      type="abnormalConfig"
      @setCrewOpeSancel="setCrewOpeSancel"
    />
    <!-- 新增和详情 -->
    <addBasicProcessesDialog
      :showDialog="isAddOpen"
      v-if="isAddOpen"
      @closeDialog="closeDialog"
      :title="openTitle"
      :id="rowId"
    ></addBasicProcessesDialog>
  </basic-container>
</template>
<script>
// import { getList, remove, update, add, getMenu } from '@/api/system/menu';
import { getList, remove, add } from "@/api/processManagement/basicProcesses";
import addBasicProcessesDialog from "./components/addBasicProcessesDialog.vue";
import { mapGetters } from "vuex";
import { getDictionary } from "@/api/system/dict";
import setCrew from "./components/setCrew.vue";

export default {
  components: {
    setCrew,
    addBasicProcessesDialog,
  },
  data() {
    return {
      ppsId: null,
      setCrewOpen: false,
      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,
        delBtn: false,
        editBtn: false,
        editBtnText: "修改",
        addBtnIcon: " ",
        viewBtnIcon: " ",
        delBtnIcon: " ",
        editBtnIcon: " ",
        viewBtnText: "详情",
        // labelWidth: 120,
        menuWidth: 140,
        dialogWidth: 840,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        columnSort: true,
        excelBtn: true,
        columnSort: true,
        showOverflowTooltip: true,
        searchLabelPosition: "left",
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: "left",
        gridBtn: false,
        searchMenuPosition: "right",
        align: "center",

        column: [
          {
            label: "编码",
            prop: "code",
            search: true,
            sortable: true,
            overHidden: true,
            order: 9,
            headerAlign: "center",
            align: "center",
            searchLabelWidth: 45,
            rules: [
              {
                required: true,
                message: "请输入配置码",
                trigger: "blur",
              },
            ],
          },
          {
            label: "名称",
            prop: "name",
            sortable: true,
            search: true,
            overHidden: true,
            order: 8,
            width: 200,
            headerAlign: "center",
            align: "left",
            searchLabelWidth: 45,
            rules: [
              {
                required: true,
                message: "请选择镀种分类",
                trigger: "click",
              },
            ],
          },
          {
            label: "不分派",
            prop: "isDispatch", //1:是 2:否
            sortable: true,
            search: true,
            overHidden: true,
            span: 8,
            headerAlign: "center",
            align: "center",
            searchLabelWidth: 60,
            type: "select",
            clearable: true,
            dicData: [
              {
                label: "是",
                value: "1",
              },
              {
                label: "否",
                value: "2",
              },
            ],
            rules: [
              {
                required: false,
                message: "请输入镀种",
                trigger: "click",
              },
            ],
          },
          {
            label: "特殊",
            prop: "isSpecial",
            sortable: true,
            search: true,
            overHidden: true,
            span: 8,
            headerAlign: "center",
            align: "center",
            searchLabelWidth: 45,
            type: "select",
            clearable: true,
            dicData: [
              {
                label: "是",
                value: "1",
              },
              {
                label: "否",
                value: "2",
              },
            ],
            rules: [
              {
                required: false,
                message: "请输入镀层编码",
                trigger: "click",
              },
            ],
          },
          {
            label: "主工序",
            prop: "isMain",
            sortable: true,
            search: false,
            span: 8,
            headerAlign: "center",
            align: "center",
            rules: [
              {
                required: false,
                message: "请输入镀种小类",
                trigger: "click",
              },
            ],
          },
          {
            label: "班组",
            prop: "team",
            sortable: true,
            search: false,
            overHidden: true,
            display: false,
            headerAlign: "center",
            align: "left",
            rules: [
              {
                required: false,
                message: "请输入材料",
                trigger: "click",
              },
            ],
          },
          {
            label: "标准周期",
            prop: "cycle",
            sortable: true,
            search: false,
            order: 7,
            span: 24,
            headerAlign: "center",
            align: "center",
            rules: [
              {
                required: true,
                message: "请输入标准周期",
                trigger: "click",
              },
            ],
          },
          {
            label: "电流(A)",
            prop: "eleStream",
            display: true,
            hide: true,
            span: 8,
          },
          {
            label: "电导率",
            prop: "eleRate",
            display: true,
            hide: true,
            span: 8,
          },
          {
            label: "PH",
            prop: "phValue",
            display: true,
            hide: true,
            span: 8,
          },
          {
            label: "Ni+",
            prop: "niValue",
            display: true,
            hide: true,
            span: 8,
          },
          {
            label: "转速/振频",
            prop: "vSpeed",
            display: true,
            hide: true,
            span: 6,
          },
          {
            label: "整流机控制模式",
            prop: "cyropactorControl",
            display: true,
            hide: true,
            span: 10,
          },
        ],
      },
      data: [],
      isAddOpen: false,
      openTitle: "",
      rowId: "",
    };
  },

  methods: {
    // 新增
    addFn() {
      this.isAddOpen = true;
      this.openTitle = "新增";
    },
    closeDialog(isRefresh) {
      this.isAddOpen = false;
      if (isRefresh) {
        // this.$refs.myTable.load();
        this.onLoad(this.page, this.query);
      }
    },
    detailsFn(row) {
      this.openTitle = "详情";
      this.isAddOpen = true;
      this.rowId = row.id;
    },
    // 设置班组人员
    setCrew(row) {
      this.rowId = row.id;
      this.setCrewOpen = true;
    },
    // 设置班组人员弹框关闭
    setCrewOpeSancel(isRefresh) {
      if (isRefresh) {
        this.$refs.myTable.load();
      }
      this.setCrewOpen = false;
    },

    // 重置
    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();
    },

    // 切换 页码
    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>
