<template>
  <div>
    <el-table :data="tableData">
      <el-table-column label="序号" prop="idx" align="center" />
      <el-table-column label="工序名称" prop="processName" align="center" />
      <el-table-column label="工作中心" prop="workstationName" align="center" />
      <el-table-column label="标准工时" prop="stdWorkingTime" align="center" />
      <el-table-column label="换型时间" prop="lineBreakTime" align="center" />
      <el-table-column
        label="工时单位"
        prop="stdWorkingTimeUom"
        align="center"
      />
      <el-table-column
        label="加工方式"
        prop="processingMethod"
        align="center"
        width="215"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.process_control_code"
            :value="scope.row.processingMethod"
          />
        </template>
      </el-table-column>
      <el-table-column label="基本数量" prop="quantity" align="center" />
      <el-table-column label="固化时间" prop="solidifyTime" align="center" />
      <el-table-column label="计量单位" prop="unitOfMeasure" align="center" />
      <el-table-column label="雇员数量" prop="employeesNum" align="center" />
      <el-table-column label="关键工序" prop="keyFlag" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.keyFlag"
          />
        </template>
      </el-table-column>
      <el-table-column label="是否质检" prop="isCheck" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.isCheck"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机开边" prop="sacmForEdgeOpening" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForEdgeOpening"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机粘贴复合" prop="sacmForPasteComposite" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForPasteComposite"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机热复合" prop="sacmForThermalComposite" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForThermalComposite"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机贴标" prop="sacmForLabeling" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForLabeling"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机装扣" prop="sacmForBuckleUp" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForBuckleUp"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机压痕" prop="sacmForCreasing" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForCreasing"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机风琴" prop="sacmForOrgan" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForOrgan"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机热切" prop="sacmForThermalCutting" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForThermalCutting"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机热自合" prop="sacmForThermalSelfFusion" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForThermalSelfFusion"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机压齿" prop="sacmForMolarTooth" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForMolarTooth"
          />
        </template>
      </el-table-column>
      <el-table-column label="封切机分切" prop="sacmForSlitting" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.sacmForSlitting"
          />
        </template>
      </el-table-column>
      <el-table-column label="工序备注" prop="processRemark" align="center" />
      <el-table-column
        v-if="mode != 'info'"
        label="操作"
        align="center"
        width="300"
        fixed="right"
      >
        <template slot-scope="{ row, $index }">
          <el-button type="text" size="small" @click="openSetProd(row, $index)">
            设置物料
          </el-button>
          <el-button
            type="text"
            size="small"
            @click="openSetQrindex(row, $index)"
          >
            设置检验项
          </el-button>
          <el-button type="text" size="small" @click="openSetTool(row, $index)">
            设置工装量具
          </el-button>
          <el-button type="text" size="small" @click="updateRow(row, $index)"
            >修改</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        v-if="mode == 'info'"
        label="操作"
        align="center"
        width="310"
        fixed="right"
      >
        <template slot-scope="{ row, $index }">
          <el-button type="text" size="small" @click="SearchProd(row, $index)">
            查看物料
          </el-button>
          <el-button
            type="text"
            size="small"
            @click="searchQrindex(row, $index)"
          >
            查看检验项
          </el-button>
          <el-button type="text" size="small" @click="searchTool(row, $index)">
            查看工装量具
          </el-button>
          <el-button type="text" size="small" @click="searchRow(row, $index)"
            >查看工序信息</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <ProcessProd
      :process="currentRow"
      :bomList="bomList"
      ref="ProcessProdRef"
      @updateItem="updateItem"
    />
    <ProcessQcindex :process="currentRow" ref="ProcessQcindexRef" />
    <ProcessTool :process="currentRow" ref="ProcessToolRef" />

    <el-dialog
      v-dialogDrag
      :visible.sync="showFlag"
      width="800px"
      title="工序设置"
    >
      <el-form
        ref="form"
        class="page-form"
        :model="form"
        size="small"
        :inline="true"
        label-width="8em"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="工作中心" prop="workstationId">
              <el-input
                v-model="form.workstationName"
                disabled
                placeholder="请选择工作中心信息"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  @click="handleWorkstationSelect"
                ></el-button>
              </el-input>
              <WorkstationSelect
                ref="WorkstationSelect"
                :processId="form.processId"
                @onSelected="onWorkstationSelected"
              ></WorkstationSelect>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标准工时" prop="stdWorkingTime">
              <el-input
                type="number"
                v-model="form.stdWorkingTime"
                placeholder="请输入标准工时"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="换型时间" prop="lineBreakTime">
              <el-input
                type="number"
                v-model="form.lineBreakTime"
                placeholder="请输入换型时间"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工时单位" prop="stdWorkingTimeUom">
              <el-select
                v-model="form.stdWorkingTimeUom"
                clearable
                placeholder="请选择工时单位"
              >
                <el-option
                  v-for="dict in dict.type.mes_time_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="基本数量" prop="quantity">
              <el-input
                type="number"
                v-model="form.quantity"
                placeholder="请输入基本数量"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工序计量单位" prop="unitOfMeasure">
              <el-input
                v-model="form.unitOfMeasure"
                placeholder="请输入工序计量单位"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="副单位" prop="deputyUnitOfMeasure">
              <el-input
                v-model="form.deputyUnitOfMeasure"
                placeholder="请输入副单位"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="固化时间" label-width="120px" prop="solidifyTime">
              <el-input v-model="form.solidifyTime" placeholder="请输入固化时间">
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px; color: #1e1e1e">MIN</i>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="单位转换比例" prop="unitConvert">
              <el-input
                type="number"
                v-model="form.unitConvert"
                placeholder="请输入主副单位转换比例"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="雇员数量" prop="employeesNum">
              <el-input
                type="number"
                v-model="form.employeesNum"
                placeholder="请输入雇员数量"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="加工方式" prop="processingMethod">
              <el-select
                v-model="form.processingMethod"
                placeholder="请选择加工方式"
                clearable
                style="width: 150px"
              >
                <el-option
                  v-for="dict in dict.type.process_control_code"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="form.processingMethod == 'PP02'">
            <el-col :span="12">
              <el-form-item
                label="采购信息记录号"
                prop="procurementInformationId"
              >
                <el-input
                  v-model="form.procurementInformationId"
                  placeholder="请输入采购信息记录号"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供应商科目编号" prop="vendorSubjectId">
                <el-input
                  v-model="form.vendorSubjectId"
                  placeholder="请输入供应商科目编号"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="净价" prop="netPrice">
                <el-input
                  v-model="form.netPrice"
                  placeholder="请输入净价"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购组织" prop="procurementOrganization">
                <el-input
                  v-model="form.procurementOrganization"
                  placeholder="请输入采购组织"
                ></el-input>
              </el-form-item>
            </el-col>
          </template>
          <el-col :span="12">
            <el-form-item label="关键工序" prop="keyFlag">
              <el-select
                v-model="form.keyFlag"
                placeholder="请选择是否为关键工序"
                clearable
                style="width: 150px"
              >
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否质检" prop="isCheck">
              <el-select
                v-model="form.isCheck"
                placeholder="请选择是否质检"
                clearable
                style="width: 150px"
              >
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-form-item>
          <el-checkbox
            v-model="form.sacmForEdgeOpening"
            true-label="Y"
            false-label="N"
            >开边</el-checkbox>
            <el-checkbox
            v-model="form.sacmForPasteComposite"
            true-label="Y"
            false-label="N"
            >粘贴符合</el-checkbox>
            <el-checkbox
            v-model="form.sacmForThermalComposite"
            true-label="Y"
            false-label="N"
            >热复合</el-checkbox>
            <el-checkbox
            v-model="form.sacmForLabeling"
            true-label="Y"
            false-label="N"
            >粘标</el-checkbox>
            <el-checkbox
            v-model="form.sacmForBuckleUp"
            true-label="Y"
            false-label="N"
            >装扣</el-checkbox>
            <el-checkbox
            v-model="form.sacmForCreasing"
            true-label="Y"
            false-label="N"
            >压痕</el-checkbox>
            <el-checkbox
            v-model="form.sacmForOrgan"
            true-label="Y"
            false-label="N"
            >风琴</el-checkbox>
            <el-checkbox
            v-model="form.sacmForThermalCutting"
            true-label="Y"
            false-label="N"
            >热切</el-checkbox>
            <el-checkbox
            v-model="form.sacmForThermalSelfFusion"
            true-label="Y"
            false-label="N"
            >热自合</el-checkbox>
            <el-checkbox
            v-model="form.sacmForMolarTooth"
            true-label="Y"
            false-label="N"
            >压齿</el-checkbox>
            <el-checkbox
            v-model="form.sacmForSlitting"
            true-label="Y"
            false-label="N"
            >分切</el-checkbox>
         </el-form-item> 
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input
                type="textarea"
                v-model="form.remark"
                placeholder="请输入工序备注"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button type="default" @click="showFlag = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import ItemBomSelect from "@/components/itemBomSelect/single.vue";
import ProcessProd from "./ProcessProd.vue";
import ProcessQcindex from "./ProcessQcindex.vue";
import ProcessTool from "./ProcessTool.vue";
import WorkstationSelect from "@/components/workstationSelect/simpletableSingle.vue";
export default {
  components: {
    ItemBomSelect,
    ProcessProd,
    ProcessQcindex,
    ProcessTool,
    WorkstationSelect,
  },
  inject: ["mode"],
  dicts: [
    "process_control_code",
    "sys_yes_no",
    "mes_time_type",
    "product_shape",
  ],
  props: {
    bomList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      /**弹窗状态 */
      showFlag: false,
      /**表格数据 */
      tableData: [],
      /**表单规则 */
      rules: {},
      /**表单初始化数据 */
      form: {
        productionSolutionId: "",
        recordId: "",
        processId: "",
        workstationId: "",
        keyFlag: "",
        isCheck: "",
        idx: "",
        workstationCode: "",
        processingMethod: "",
        processName: "",
        processRemark: "",
        quantity: "",
        unitOfMeasure: "",
        employeesNum: "",
        stdWorkingTime: "",
        lineBreakTime: "",
        stdWorkingTimeUom: "",
        procurementInformationId: "",
        vendorSubjectId: "",
        netPrice: "",
        procurementOrganization: "",
        remark: "",
        deputyUnitOfMeasure: "",
        unitConvert: "",
        sacmForEdgeOpening: '',
               sacmForPasteComposite: '',
               sacmForThermalComposite: '',
               sacmForLabeling: '',
               sacmForBuckleUp: '',
               sacmForCreasing: '',
               sacmForOrgan: '',
               sacmForThermalCutting: '',
               sacmForThermalSelfFusion: '',
               sacmForMolarTooth: '',
               sacmForSlitting: '',
      },
      currentRow: {},
      currentRowIndex: undefined,
    };
  },
  methods: {
    setList(rows) {
      this.tableData = rows.map((item) => {
        item.processItemList = [];
        item.qcindexList = [];
        item.toolList = [];
        return item;
      });
    },
    /** 更新工序的物料信息 */
    updateItem(items) {
      this.tableData[this.currentRowIndex].processItemList = items;
    },
    openSetProd(row, idx) {
      this.currentRow = row;
      this.currentRowIndex = idx;
      this.$refs["ProcessProdRef"].showProcessProd = true;
    },
    openSetQrindex(row, idx) {
      this.currentRow = row;
      this.currentRowIndex = idx;
      this.$refs["ProcessQcindexRef"].showProcessProd = true;
    },
    openSetTool(row, idx) {
      this.currentRow = row;
      this.currentRowIndex = idx;
      this.$refs["ProcessToolRef"].showProcessProd = true;
    },
    /**查看物料 */
    SearchProd(row, idx) {
      this.currentRow = row;
      this.currentRowIndex = idx;
      this.$refs["ProcessProdRef"].optType = "detail";
      this.$refs["ProcessProdRef"].showProcessProd = true;
    },
    /**查看行 */
    searchRow(row, idx) {
      this.form = Object.assign(this.form, row);
      this.currentRowIdx = idx;
      this.optType = "detail";
      this.showFlag = true;
    },
    /**查看质检 */
    searchQrindex(row, idx) {
      this.currentRow = row;
      this.currentRowIndex = idx;
      this.$refs["ProcessQcindexRef"].optType = "detail";
      this.$refs["ProcessQcindexRef"].showProcessProd = true;
    },
    /**查看工装 */
    searchTool(row, idx) {
      this.currentRow = row;
      this.currentRowIndex = idx;
      this.$refs["ProcessToolRef"].optType = "detail";
      this.$refs["ProcessToolRef"].showProcessProd = true;
    },
    /**更新行 */
    updateRow(row, idx) {
      Object.assign(this.form, row);
      this.currentRowIndex = idx;
      this.showFlag = true;
    },
    /**表单提交 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.showFlag = false;
          this.tableData.splice(this.currentRowIndex, 1, {
            ...this.currentRow,
            ...this.form,
          });
        }
      });
    },
    getComData() {
      return this.tableData;
    },
    /**重置表单 */
    resetForm() {
      this.form = {
        productionSolutionId: "",
        recordId: "",
        processId: "",
        workstationId: "",
        keyFlag: "",
        isCheck: "",
        idx: "",
        workstationCode: "",
        processingMethod: "",
        processName: "",
        processRemark: "",
        quantity: "",
        unitOfMeasure: "",
        employeesNum: "",
        stdWorkingTime: "",
        lineBreakTime: "",
        stdWorkingTimeUom: "",
        procurementInformationId: "",
        vendorSubjectId: "",
        netPrice: "",
        procurementOrganization: "",
        remark: "",
        deputyUnitOfMeasure: "",
        unitConvert: "",
        sacmForEdgeOpening: '',
               sacmForPasteComposite: '',
               sacmForThermalComposite: '',
               sacmForLabeling: '',
               sacmForBuckleUp: '',
               sacmForCreasing: '',
               sacmForOrgan: '',
               sacmForThermalCutting: '',
               sacmForThermalSelfFusion: '',
               sacmForMolarTooth: '',
               sacmForSlitting: '',
             
      };
    },
    /**重置组件状态 */
    resetState() {
      this.resetForm();
      this.tableData = [];
    },
    // 查询工作中心信息
    handleWorkstationSelect() {
      this.$refs.WorkstationSelect.showFlag = true;
    },
    onWorkstationSelected(row) {
      if (row != undefined && row != null) {
        this.form.workstationId = row.workstationId;
        this.form.workstationName = row.workstationName;
        this.form.stdWorkingTime = row.stdWorkingTime;
      }
    },
  },
};
</script>

<style></style>
