<template>
  <div>
    <!-- <el-row :gutter="10" class="mb8" v-if="mode != 'info'">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
    </el-row> -->

    <el-table :data="tableData" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column
        label="指令列表"
        align="center"
        prop="directiveList"
        width="120"
      />
      <el-table-column label="数量" align="center" prop="num" width="120" />
      <el-table-column
        label="LOSS数"
        align="center"
        prop="lossNum"
        width="120"
      />
      <el-table-column
        label="销售凭证"
        align="center"
        prop="salesVoucher"
        width="120"
      />
      <el-table-column
        label="销售凭证项目"
        align="center"
        prop="salesVoucherItem"
        width="120"
      />
      <el-table-column
        label="客户编号"
        align="center"
        prop="clientCode"
        width="120"
      />
      <el-table-column
        label="尺码组"
        align="center"
        prop="sizeGroup"
        width="120"
      />
      <el-table-column
        label="尺码单位"
        align="center"
        prop="clientSizeUnit"
        width="120"
      />
      <el-table-column
        label="指令号"
        align="center"
        prop="clientCmd"
        width="120"
      />
      <el-table-column
        label="型体号"
        align="center"
        prop="typeNo"
        width="120"
      />
      <el-table-column
        label="配色号"
        align="center"
        prop="colorNo"
        width="120"
      />
      <el-table-column label="颜色" align="center" prop="color" width="120" />
      <el-table-column
        label="销线"
        align="center"
        prop="salePath"
        width="120"
      />
      <el-table-column label="段别" align="center" prop="segment" width="120" />
      <el-table-column label="季度" align="center" prop="quarter" width="120" />
      <el-table-column
        label="整/半码"
        align="center"
        prop="wholeSize"
        width="120"
      />
      <el-table-column
        label="特殊SIZE"
        align="center"
        prop="specSize"
        width="120"
      />
      <el-table-column label="PO#" align="center" prop="poNo" width="120" />
      <el-table-column label="WIP#" align="center" prop="wipNo" width="120" />
      <el-table-column
        label="装箱数"
        align="center"
        prop="packingNum"
        width="120"
      />
      <el-table-column label="产地" align="center" prop="region" width="120" />
      <el-table-column label="周期" align="center" prop="cycle" width="120" />
      <el-table-column label="SK编号" align="center" prop="skNo" width="120" />
      <el-table-column
        label="专利号 CHAR 50"
        align="center"
        prop="patentNo"
        width="120"
      />
      <el-table-column
        label="材质描述"
        align="center"
        prop="materialDesc"
        width="120"
      />
      <el-table-column
        label="签收人"
        align="center"
        prop="signer"
        width="120"
      />
      <el-table-column
        label="SHIP TO ID"
        align="center"
        prop="shipToId"
        width="120"
      />
      <el-table-column
        label="产品规格"
        align="center"
        prop="prodSpec"
        width="120"
      />
      <el-table-column
        label="产品用途"
        align="center"
        prop="prodUsage"
        width="120"
      />
      <el-table-column
        label="厚度（丝）"
        align="center"
        prop="thickness"
        width="120"
      />
      <el-table-column
        label="包装方式"
        align="center"
        prop="packMode"
        width="120"
      />
      <el-table-column
        label="印刷方向"
        align="center"
        prop="printingDirection"
        width="120"
      />
      <el-table-column
        label="工厂代号"
        align="center"
        prop="plantCode"
        width="120"
      />
      <!-- <el-table-column
        v-if="mode != 'info'"
        label="操作"
        align="center"
        width="120"
      >
        <template slot-scope="{ row, $index }">
          <el-button
            type="text"
            icon="el-icon-edit"
            size="small"
            @click="updateRow(row, $index)"
            >修改</el-button
          >
          <el-button
            type="text"
            icon="el-icon-delete"
            size="small"
            @click="deleteRow($index)"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>
  </div>
</template>

<script>
export default {
  components: {},
  inject: ["mode"],
  data() {
    return {
      /**弹窗状态 */
      showFlag: false,
      /**表格数据 */
      tableData: [],
      /**表单规则 */
      rules: {},
      /**多选 */
      selection: [],
      optType: "add",
      /**表单初始化数据 */
      form: {
        directiveList: "",
        num: "",
        lossNum: "",
        salesVoucher: "",
        salesVoucherItem: "",
        clientCode: "",
        sizeGroup: "",
        clientSizeUnit: "",
        clientCmd: "",
        typeNo: "",
        colorNo: "",
        color: "",
        salePath: "",
        segment: "",
        quarter: "",
        wholeSize: "",
        specSize: "",
        poNo: "",
        wipNo: "",
        packingNum: "",
        region: "",
        cycle: "",
        skNo: "",
        patentNo: "",
        materialDesc: "",
        signer: "",
        shipToId: "",
        prodSpec: "",
        prodUsage: "",
        thickness: "",
        packMode: "",
        printingDirection: "",
        plantCode: "",
      },
      currentRowIdx: undefined,
    };
  },
  created() {},
  methods: {
    /**多选 */
    handleSelectionChange(val) {
      this.selection = val;
    },
    /**删除操作 */
    handleDelete() {},
    /**添加操作 */
    handleAdd() {
      this.resetForm();
      this.showFlag = true;
      this.optType = "add";
    },
    /**更新行 */
    updateRow(row, idx) {
      Object.assign(this.form, row);
      this.currentRowIdx = idx;
      this.optType = "edit";
      this.showFlag = true;
    },
    /**删除行 */
    deleteRow(index) {
      this.tableData.splice(index, 1);
    },
    /**表单提交 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.optType == "add") {
            this.tableData.unshift({ ...this.form });
          } else {
            this.tableData.splice(this.currentRowIdx, 1, this.form);
          }
          this.showFlag = false;
        }
      });
    },
    /**重置表单 */
    resetForm() {
      this.form = {
        directiveList: "",
        num: "",
        lossNum: "",
        salesVoucher: "",
        salesVoucherItem: "",
        clientCode: "",
        sizeGroup: "",
        clientSizeUnit: "",
        clientCmd: "",
        typeNo: "",
        colorNo: "",
        color: "",
        salePath: "",
        segment: "",
        quarter: "",
        wholeSize: "",
        specSize: "",
        poNo: "",
        wipNo: "",
        packingNum: "",
        region: "",
        cycle: "",
        skNo: "",
        patentNo: "",
        materialDesc: "",
        signer: "",
        shipToId: "",
        prodSpec: "",
        prodUsage: "",
        thickness: "",
        packMode: "",
        printingDirection: "",
        plantCode: "",
      };
    },
    /**重置组件状态 */
    resetState() {
      this.resetForm();
      this.tableData = [];
    },
    /**获取组件数据 */
    getComData() {
      return this.tableData;
    },
  },
};
</script>

<style></style>
