<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 #userName="{ row }">{{ row.leaderUser.userName }}</template>
      <template #jcName="{ row }">{{ row.bsJfCenter.jcName }}</template>
      <template #menu-left>
        <el-button type="danger" icon="el-icon-delete" @click="handleDelete"
          >删除</el-button
        >
      </template>
      <template #menu="{ row }">
        <el-button type="text" @click="setTeam(row)">设置班组</el-button>
        <el-button type="text">设置工艺能力</el-button>
      </template>
    </avue-crud>
    <el-dialog title="设置班组" append-to-body v-model="teamDialog" width="700">
      <el-transfer
        style="width: 100%"
        v-model="teamValue"
        :data="teamData"
        :titles="['未选择', '已选择']"
        :props="{
          key: 'tsId',
          label: 'tsName',
        }"
      ></el-transfer>
    </el-dialog>
    <el-dialog title="设置工艺能力" append-to-body v-model="capacityDialog" width="60%">
      <div>
        <el-button type="primary" icon="el-icon-plus" @click="insertEvent()"
          >插入一行</el-button
        >
        <el-button plain type="danger" @click="remove">删除选择行</el-button>
        <el-button type="primary" @click="handleSave">保存</el-button>
      </div>
      <div style="margin-top: 20px">
        <el-table
          :data="capacityList"
          @selection-change="selectionChangeProject"
          @select="selectChange"
        >
          <el-table-column type="selection" width="55px"></el-table-column>
          <el-table-column align="center" label="工艺能力" prop="caId">
            <template #default="scope">
              <el-select v-model="scope.row.caId">
                <el-option label="不锈钢涂福斯润滑剂" value="306"></el-option>
                <el-option label="真空镀铬" value="321"></el-option>
                <el-option label="试键位" value="146"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" label="面积" prop="area">
            <template #default="scope">
              <el-input v-model="scope.row.area"></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="数量" prop="quantity">
            <template #default="scope">
              <el-input v-model="scope.row.quantity"></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="批次" prop="batchNo">
            <template #default="scope">
              <el-input v-model="scope.row.batchNo"></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="饱和度(%)" prop="saturation">
            <template #default="scope">
              <el-input v-model="scope.row.saturation"></el-input>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </basic-container>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      data: [],
      form: {},
      capacityList: [],
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      teamValue: [],
      capacityDialog: false,
      teamData: [
        {
          tsId: "104",
          tsName: "吹砂班",
        },
        {
          tsId: "123",
          tsName: "喷砂班",
        },
        {
          tsId: "126",
          tsName: "超声波清洗班",
        },
        {
          tsId: "127",
          tsName: "涂色带班",
        },
        {
          tsId: "128",
          tsName: "湿喷砂",
        },
        {
          tsId: "142",
          tsName: "12",
        },
        {
          tsId: "162",
          tsName: "外协镀前出库班",
        },
        {
          tsId: "182",
          tsName: "玻璃烧结班组",
        },
        {
          tsId: "124",
          tsName: "镀金二班白龙喜",
        },
        {
          tsId: "125",
          tsName: "镀金二班杜宁",
        },
        {
          tsId: "102",
          tsName: "镀金一班郭千千",
        },
        {
          tsId: "103",
          tsName: "镀金一班张二帅",
        },
      ],
      teamDialog: false,
      selectionList: [],
      option: {
        columnSort: true,
        tip: false,
        height: "auto",
        align: "center",
        rowKey: "wcCode",
        calcHeight: 32,
        simplePage: false,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: false,
        selection: true,
        viewBtn: false,
        delBtn: false,
        editBtn: true,
        editBtnText: "修改",
        editBtnIcon: " ",
        delBtnIcon: " ",
        addBtn: true,
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 300,
        dialogWidth: 800,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: true,
        gridBtn: false,
        searchShowBtn: false,
        showOverflowTooltip: true,
        searchLabelPosition: "left",
        searchLabelPosition: "left",
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: "left",
        gridBtn: false,
        searchMenuPosition: "right",
        addBtnIcon: " ",
        viewBtnIcon: " ",
        delBtnIcon: " ",
        editBtnIcon: " ",
        column: [
          {
            label: "编码",
            prop: "wcCode",
            span: 24,
            overflow: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入编码",
                trigger: "blur",
              },
            ],
          },
          {
            label: "名称",
            prop: "wcName",
            span: 24,
            overflow: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入名称",
                trigger: "blur",
              },
            ],
          },
          {
            label: "工序",
            prop: "processes",
            span: 24,
            hide: true,
            addDisplay: false,
            editDisplay: false,
            overflow: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入工序",
                trigger: "blur",
              },
            ],
          },
          {
            label: "工艺能力",
            prop: "craftAbility",
            span: 24,
            overflow: true,
            search: false,
            addDisplay: false,
            editDisplay: false,
            rules: [
              {
                required: true,
                message: "请输入工艺能力",
                trigger: "blur",
              },
            ],
          },
          {
            label: "业务标识",
            prop: "sign",
            span: 24,
            overflow: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入业务标识",
                trigger: "blur",
              },
            ],
          },
          {
            label: "主管工艺员",
            prop: "userName",
            type: "select",
            span: 24,
            overflow: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入主管工艺员",
                trigger: "blur",
              },
            ],
            dicData: [
              { userName: "00188", userId: 441 },
              { userName: "00660", userId: 322 },
              { userName: "00698", userId: 451 },
            ],
            props: {
              label: "userName",
              value: "userId",
            },
          },
          {
            label: "班组",
            prop: "team",
            span: 24,
            addDisplay: false,
            editDisplay: false,
            overflow: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入班组",
                trigger: "blur",
              },
            ],
          },
          {
            label: "交付中心",
            prop: "jcName",
            span: 24,
            overflow: true,
            search: false,
            rules: [
              {
                required: true,
                message: "请输入交付中心",
                trigger: "blur",
              },
            ],
          },
          {
            label: "描述",
            prop: "describe",
            type: "textarea",
            span: 24,
            hide: true,
            overflow: true,
            search: false,
            // rules: [
            //     {
            //         required: true,
            //         message: '请输入交付中心',
            //         trigger: 'blur',
            //     },
            // ],
          },
          {
            label: "",
            prop: "checkout",
            type: "checkbox",
            dicData: [{ label: "检验标记", value: 0 }],
            span: 8,
            hide: true,
            overflow: true,
            search: false,
            // rules: [
            //     {
            //         required: true,
            //         message: '请输入交付中心',
            //         trigger: 'blur',
            //     },
            // ],
          },
          {
            label: "",
            prop: "whetherPlate",
            type: "checkbox",
            dicData: [{ label: "镀后标记", value: 0 }],
            span: 8,
            hide: true,
            overflow: true,
            search: false,
            // rules: [
            //     {
            //         required: true,
            //         message: '请输入交付中心',
            //         trigger: 'blur',
            //     },
            // ],
          },
          {
            label: "",
            prop: "bigBatch",
            type: "checkbox",
            dicData: [{ label: "是否大批量", value: 0 }],
            span: 8,
            hide: true,
            overflow: true,
            search: false,
            // rules: [
            //     {
            //         required: true,
            //         message: '请输入交付中心',
            //         trigger: 'blur',
            //     },
            // ],
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    // 设置班组
    setTeam(row) {
      this.teamValue = row.teamValue.split(",");
      console.log("teamValue=================", this.teamValue);
      this.teamDialog = true;
    },
    // 工艺能力插入一行
    insertEvent() {
      const record = { _select: false };
      this.capacityList.push(record);
    },
    selectChange(list, row) {
      row._select = !row._select;
    },
    remove() {
      let arr = this.capacityList.filter((item) => item._select);
      if (arr.length != 0) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          if (this.rowId) {
            let deleteData = this.capacityList.filter((item) => item._select);
            this.deleteTidArr = deleteData.filter((item) => item.tidId);
          }
          let deleteArr = this.capacityList.filter((item) => !item._select);
          this.capacityList = deleteArr;
        });
      } else {
        this.$message.error("请至少选择一条数据进行操作！");
      }
    },
    handleSave() {
      //   if(this.capacityList.length == 0){
      //     this.$message.error('请至少填写一条数据')
      //   }else{
      //     // let tmp = this.capacityList.find(item => !item.oneData || !item.twoData)
      //     // if(tmp){
      //     //     this.$message.error('数据请填写完整!')
      //     // }
      //   }
      this.capacityDialog = false;
    },
    selectionChange(val) {
      this.selectionList = val;
    },
    handleDelete() {
      if (this.selectionList.length == 0) {
        this.$message.error("请至少选择一条数据");
      } else {
        this.$confirm("确定删除选中数据?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {});
      }
    },
    onLoad() {
      this.data = [
        {
          area: 0.0,
          batchNo: null,
          bigBatch: false,
          bsJfCenter: {
            createMan: null,
            createTime: null,
            deleted: false,
            jcCode: "SJZX",
            jcId: 2,
            jcName: "烧结中心",
            keyValue: 2,
            updateTime: null,
          },
          checkout: false,
          craftAbility: null,
          createMan: {
            userId: 1,
            userName: "admin",
          },
          deleted: false,
          describe: null,
          endPoint: null,
          keyValue: 222,
          leaderUser: {
            userId: 280,
            userName: "01152",
          },
          limitType: 0,
          processes: " ",
          quantity: 0,
          roundCycle: null,
          saturation: 0.0,
          sign: "test",
          startPoint: null,
          teamValue: "",
          team: " ",
          wcCode: "11",
          wcId: 222,
          wcName: "测试中心",
          whetherPlate: false,
        },
        {
          area: 0.0,
          batchNo: null,
          bigBatch: false,
          bsJfCenter: {
            createMan: null,
            createTime: null,
            deleted: false,
            jcCode: "WXZX",
            jcId: 3,
            jcName: "外协中心",
            keyValue: 3,
            updateTime: null,
          },
          checkout: false,
          craftAbility: "玻璃烧结电镀、玻璃烧结、烧结后检验",
          createMan: {
            userId: 541,
            userName: "崔殿龙",
          },
          deleted: false,
          describe: null,
          endPoint: null,
          keyValue: 202,
          leaderUser: {
            userId: 541,
            userName: "崔殿龙",
          },
          limitType: 0,
          processes: " ",
          quantity: 0,
          roundCycle: null,
          saturation: 0.0,
          sign: "1",
          startPoint: null,
          team: "玻璃烧结班组",
          teamValue: "182",
          wcCode: "010",
          wcId: 202,
          wcName: "玻璃烧结作业中心",
          whetherPlate: false,
        },
        {
          area: 0.0,
          batchNo: null,
          bigBatch: false,
          bsJfCenter: {
            createMan: null,
            createTime: null,
            deleted: false,
            jcCode: "SJZX",
            jcId: 2,
            jcName: "烧结中心",
            keyValue: 2,
            updateTime: null,
          },
          checkout: false,
          craftAbility: "滚镀金或振镀金、超声波清洗",
          createMan: {
            userId: 90,
            userName: "03891",
          },
          deleted: false,
          describe: null,
          endPoint: null,
          keyValue: 162,
          leaderUser: {
            userId: 541,
            userName: "崔殿龙",
          },
          limitType: 0,
          processes: " ",
          quantity: 0,
          roundCycle: null,
          saturation: 0.0,
          sign: "4",
          startPoint: null,
          team: "镀金二班白龙喜、镀金二班杜宁",
          teamValue: "124,125",
          wcCode: "009",
          wcId: 162,
          wcName: "镀金小批量作业中心",
          whetherPlate: false,
        },
        {
          area: 0.0,
          batchNo: null,
          bigBatch: true,
          bsJfCenter: {
            createMan: {
              userId: 1,
              userName: "admin",
            },
            createTime: "2024-12-09 00:00:00",
            deleted: false,
            jcCode: "RBZX",
            jcId: 1,
            jcName: "热表中心",
            keyValue: 1,
            updateTime: "2024-12-09 00:00:00",
          },
          checkout: false,
          craftAbility: "滚镀金或振镀金",
          createMan: {
            userId: 90,
            userName: "03891",
          },
          deleted: false,
          describe: null,
          endPoint: null,
          keyValue: 122,
          leaderUser: {
            userId: 541,
            userName: "崔殿龙",
          },
          limitType: 0,
          processes: " ",
          quantity: 0,
          roundCycle: null,
          saturation: 0.0,
          sign: "4",
          startPoint: null,
          team: "镀金一班郭千千、镀金一班张二帅",
          teamValue: "102,103",
          wcCode: "008",
          wcId: 122,
          wcName: "镀金大批量作业中心",
          whetherPlate: false,
        },
      ];
      this.page.total = this.data.length;
    },
  },
};
</script>
