<template>
  <basic-container>
    <!-- 添加量填报 -->
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @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 type="primary" @click="handleAdd">新增</el-button>
      </template>

      <template #menu="scope">
        <el-button type="text" @click="editRow(scope.row)">修改</el-button>
        <el-button type="text" @click="deleteRow(scope.row)">删除</el-button>
      </template>
    </avue-crud>
    <el-dialog :title="title" append-to-body v-model="showDialog" width="80%">
      <div style="margin-bottom: 10px">
        <el-button type="primary"  @click="insertEvent()">插入一行</el-button>
        <el-button plain type="danger" @click="remove">删除选择行</el-button>
      </div>
      <el-table :data="tableData" @select="selectChange">
        <el-table-column type="selection"></el-table-column>
        <el-table-column align="center" label="作业中心" prop="wcId">
          <template #header>
            <span><i style="color: red">*</i>作业中心</span>
          </template>
          <template #default="scope">
            <el-select v-model="scope.row.wcId">
              <el-option
                v-for="item in wcData"
                :key="item.wcId"
                :value="item.wcId"
                :label="item.wcName"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" label="槽号槽名" prop="batchNo">
          <template #header>
            <span><i style="color: red">*</i>槽号槽名</span>
          </template>
          <template #default="scope">
            <el-select v-model="scope.row.batchNo">
              <el-option label="#21" value="1"></el-option>
              <el-option label="11" value="11"></el-option>
              <el-option label="1234" value="1234"></el-option>
              <el-option label="123" value="123"></el-option>
              <el-option label="#22" value="3"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" label="添加量" prop="addValue">
          <template #header>
            <span><i style="color: red">*</i>添加量</span>
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.addValue"></el-input>
          </template>
        </el-table-column>
        <el-table-column align="center" label="添加日期" prop="addTime">
          <template #header>
            <span><i style="color: red">*</i>添加日期</span>
          </template>
          <template #default="scope">
            <el-date-picker v-model="scope.row.addTime" type="datetime" placeholder="选择日期时间">
            </el-date-picker>
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="closeDialog">取 消</el-button>
          <el-button type="primary" @click="handleSave">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </basic-container>
</template>

<script>
import { getList, add, remove, update } from '@/api/processManagement/addQuantity.js';
export default {
  data() {
    return {
      query: {},
      loading: false,
      title: '新增',
      tableData: [],
      showDialog: false,
      data: [],
      form: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      wcData: [
        {
          area: 13000.0,
          batchNo: null,
          bigBatch: false,
          checkout: false,
          craftAbility: '化学镀镍',
          createTime: '2023-02-06 12:31:36',
          deleted: false,
          describe: null,
          endPoint: null,
          keyValue: 81,
          limitType: 0,
          processes: '上挂、下挂、交检、化学镀镍、喷砂',
          quantity: null,
          roundCycle: null,
          saturation: 85.0,
          sign: '4',
          startPoint: null,
          team: '化学镀镍一班崔胜伟、化学镀镍一班郭家梁',
          updateTime: '2023-03-06 18:42:47',
          wcCode: '001',
          wcId: 81,
          wcName: '化学镀镍作业中心',
          whetherPlate: false,
        },
        {
          area: 0.0,
          batchNo: null,
          bigBatch: false,
          checkout: false,
          craftAbility: '镀后接收',
          createTime: '2023-02-06 12:48:41',
          deleted: false,
          describe: null,
          endPoint: null,
          keyValue: 85,
          limitType: 0,
          processes: '镀后接收',
          quantity: null,
          roundCycle: null,
          saturation: null,
          sign: '4',
          startPoint: null,
          team: '零件管理班',
          updateTime: '2023-03-06 18:23:20',
          wcCode: '004',
          wcId: 85,
          wcName: '镀后库作业中心',
          whetherPlate: true,
        },
        {
          area: 0.0,
          batchNo: null,
          bigBatch: false,
          checkout: true,
          craftAbility: '镀后检验',
          createTime: '2023-02-06 12:49:33',
          deleted: false,
          describe: null,
          endPoint: null,
          keyValue: 86,
          limitType: 0,
          processes: '镀后检验、性能检测、镀后自检外观检验、镀后自检尺寸检验',
          quantity: null,
          roundCycle: null,
          saturation: null,
          sign: '4',
          startPoint: null,
          team: '检验班',
          updateTime: '2023-06-06 15:07:27',
          wcCode: '005',
          wcId: 86,
          wcName: '检验作业中心',
          whetherPlate: false,
        },
        {
          area: 20000.0,
          batchNo: null,
          bigBatch: false,
          checkout: false,
          craftAbility: '涂色标、清洗',
          createTime: '2023-02-07 10:30:14',
          deleted: false,
          describe: null,
          endPoint: null,
          keyValue: 87,
          limitType: 0,
          processes: '涂色标、涂色标（带）',
          quantity: null,
          roundCycle: null,
          saturation: 90.0,
          sign: '4',
          startPoint: null,
          team: '涂色标班组',
          updateTime: '2023-03-06 18:16:54',
          wcCode: '006',
          wcId: 87,
          wcName: '涂色标作业中心',
          whetherPlate: false,
        },
      ],
      option: {
        height: 'auto',
        calcHeight: 32,
        rowKey: 'keyValue',
        tip: false,
        size: 'medium',
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        viewBtn: false,
        delBtn: false,
        addBtn: false,
        editBtn: false,
        editBtnText: '修改',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        viewBtnText: '详情',
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 140,
        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: 'wcId',
            type: 'select',
            search: true,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'left',
            searchLabelWidth: 80,
            dicUrl: '/blade-desk/bsWorkCenter/getList',
            props: {
              label: 'wcName',
              value: 'id',
            },
          },
          {
            label: '作业槽',
            prop: 'batchNo',
            search: true,
            sortable: true,
            overHidden: true,
            type: 'select',
            headerAlign: 'center',
            align: 'center',
            searchLabelWidth: 80,
            rules: [
              {
                required: true,
                message: '请输入作业槽',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '添加量',
            prop: 'addValue',
            search: false,
            sortable: true,
            overHidden: true,
            headerAlign: 'center',
            align: 'center',
          },
          {
            label: '添加时间',
            prop: 'addTime',
            search: true,
            sortable: true,
            headerAlign: 'center',
            align: 'center',
            type: 'date',
            searchRange: true,
            searchLabelWidth: 80,
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    handleAdd() {
      this.title = '新增';
      this.tableData = [];
      this.showDialog = true;
    },
    editRow(row) {
      this.tableData = [];
      this.tableData.push(row);
      this.title = '修改';
      this.showDialog = true;
    },
    deleteRow(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {});
    },
    insertEvent() {
      const record = { bsWorkCenter: { wcId: '' }, _select: false };
      this.tableData.push(record);
    },
    selectChange(list, row) {
      row._select = !row._select;
    },
    //删除所选行
    remove() {
      let arr = this.tableData.filter(item => item._select);
      if (arr.length != 0) {
        this.$confirm('确定将选择数据删除?', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          if (this.rowId) {
            let deleteData = this.tableData.filter(item => item._select);
            this.deleteProcessArr = deleteData.filter(item => item.tidId);
          }
          let deleteArr = this.tableData.filter(item => !item._select);
          this.tableData = deleteArr;
        });
      } else {
        this.$message.error('请至少选择一条数据进行操作！');
      }
    },
    handleSave() {
      this.showDialog = false;

      console.log(55555,this.tableData);
      
    },
    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>

<style></style>
