<template>
  <div v-loading="loading">
    <PageTitle>
      {{ pageTitle }}
      <!-- 申请按钮显示 -->
      <template slot="buttons" v-if="mode == 'apply'">
        <el-button size="mini" @click="resetForm">重置</el-button>
        <el-button size="mini" type="primary" @click="saveForm">提交</el-button>
      </template>

      <!-- 修改 按钮显示 -->
      <template slot="buttons" v-if="mode == 'edit'">
        <el-button size="mini" type="primary" @click="saveForm">提交</el-button>
      </template>
    </PageTitle>

    <PageWrapper>
      <el-form
        class="page-form"
        :model="form"
        ref="form"
        :rules="rules"
        size="small"
        :inline="true"
        label-width="8em"
      >
        <el-row>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="申请单编码" prop="workorderCode">
              <el-input
                disabled
                v-model="form.workorderCode"
                placeholder="自动生成"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="工单名称" prop="workorderName">
              <el-input
                v-model="form.workorderName"
                placeholder="请输入工单名称"
              />
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="来源类型" prop="orderSource">
              <el-radio-group
                v-model="form.orderSource"
                disabled
                v-if="optType == 'view'"
              >
                <el-radio
                  v-for="dict in dict.type.mes_workorder_sourcetype"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}</el-radio
                >
              </el-radio-group>
              <el-radio-group v-model="form.orderSource" v-else>
                <el-radio
                  v-for="dict in dict.type.mes_workorder_sourcetype"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col
            :lg="6"
            :md="8"
            :sm="12"
            :xs="12"
            v-if="form.orderSource == 'ORDER'"
          >
            <el-form-item label="订单编号" prop="sourceCode">
              <el-input
                v-model="form.sourceCode"
                placeholder="请输入订单编号"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="单据状态" prop="status">
              <el-select
                v-model="form.status"
                disabled
                placeholder="请选择单据状态"
              >
                <el-option
                  v-for="dict in dict.type.mes_order_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <!-- <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="单据状态" prop="status">
              <el-select v-model="form.status" disabled>
                <el-option
                  v-for="dict in dict.type.mes_order_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->

          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="工单类型" prop="workorderType">
              <el-select v-model="form.workorderType" placeholder="请选择类型">
                <el-option
                  v-for="dict in dict.type.mes_workorder_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="工艺名称" prop="routeId">
              <el-input
                v-model="form.routeName"
                readonly
                placeholder="请选择工艺路线"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  @click="$refs['RoutesProcessSelectRef'].showFlag = true"
                ></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="产品编号" prop="productCode">
              <el-input v-model="form.productCode" placeholder="请选择产品">
                <el-button
                  slot="append"
                  @click="handleSelectProduct"
                  icon="el-icon-search"
                ></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="产品名称" prop="productName">
              <el-input
                v-model="form.productName"
                placeholder="请选择产品"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="规格型号" prop="productSpc">
              <el-input
                v-model="form.productSpc"
                placeholder="请选择产品"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="单位" prop="unitOfMeasure">
              <el-input
                v-model="form.unitOfMeasure"
                placeholder="请选择产品"
                disabled
              />
            </el-form-item>
          </el-col>

          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="工单数量" prop="quantity">
              <el-input-number
                :min="1"
                v-model="form.quantity"
                placeholder="请输入生产数量"
              />
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="需求日期" prop="requestDate">
              <el-date-picker
                clearable
                v-model="form.requestDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择需求日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="批次号" prop="batchCode">
              <el-input v-model="form.batchCode" placeholder="请输入批次号" />
            </el-form-item>
          </el-col>
          <!-- <el-row v-if="form.orderSource == 'ORDER'"> -->
          <el-col
            :lg="6"
            :md="8"
            :sm="12"
            :xs="12"
            v-if="form.orderSource == 'ORDER'"
          >
            <el-form-item label="客户编码" prop="clientCode">
              <el-input v-model="form.clientCode" placeholder="请选择客户">
                <el-button
                  slot="append"
                  @click="handleSelectClient"
                  icon="el-icon-search"
                ></el-button>
              </el-input>
              <ClientSelect ref="clientSelect" @onSelected="onClientSelected">
              </ClientSelect>
            </el-form-item>
          </el-col>
          <el-col
            :lg="6"
            :md="8"
            :sm="12"
            :xs="12"
            v-if="form.orderSource == 'ORDER'"
          >
            <el-form-item label="客户名称" prop="clientName">
              <el-input
                v-model="form.clientName"
                readonly="readonly"
                placeholder="请输入客户名称"
              />
            </el-form-item>
          </el-col>

          <el-col
            :lg="6"
            :md="8"
            :sm="12"
            :xs="12"
            v-if="
              form.workorderType == 'OUTSOURCE' ||
              form.workorderType == 'PURCHASE'
            "
          >
            <el-form-item label="供应商编码" prop="vendorCode">
              <el-input v-model="form.vendorCode" placeholder="请选择供应商">
                <el-button
                  slot="append"
                  @click="handleSelectVendor"
                  icon="el-icon-search"
                ></el-button>
              </el-input>
              <VendorSelect ref="vendorSelect" @onSelected="onVendorSelected" />
            </el-form-item>
          </el-col>
          <el-col
            :lg="6"
            :md="8"
            :sm="12"
            :xs="12"
            v-if="
              form.workorderType == 'OUTSOURCE' ||
              form.workorderType == 'PURCHASE'
            "
          >
            <el-form-item label="供应商名称" prop="vendorName">
              <el-input
                v-model="form.vendorName"
                readonly="readonly"
                placeholder="请选择供应商"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :lg="6" :md="8" :sm="12" :xs="12">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row v-if="mode != 'apply'">
          <el-col>
            <el-divider content-position="center">销售信息</el-divider>
          </el-col>
        </el-row>
        <el-row v-if="mode != 'apply'">
          <el-form-item label="订单编码" prop="orderNo">
            <el-input v-model="form.orderNo" disabled />
          </el-form-item>
          <el-form-item label="产品id" prop="itemId">
            <el-input v-model="form.itemId" disabled />
          </el-form-item>
          <el-form-item label="产品代码" prop="itemNo">
            <el-input v-model="form.itemNo" disabled />
          </el-form-item>
          <el-form-item label="sap产品代码" prop="sapItemNo">
            <el-input v-model="form.sapItemNo" disabled />
          </el-form-item>
          <el-form-item label="产品名称" prop="itemName">
            <el-input v-model="form.itemName" disabled />
          </el-form-item>
          <el-form-item label="总数量" prop="totalNum">
            <el-input v-model="form.totalNum" disabled />
          </el-form-item>
          <el-form-item label="数量" prop="num">
            <el-input v-model="form.num" disabled />
          </el-form-item>
          <el-form-item label="loss数量" prop="lossNum">
            <el-input v-model="form.lossNum" disabled />
          </el-form-item>
          <el-form-item label="单价" prop="price">
            <el-input v-model="form.price" disabled />
          </el-form-item>
          <el-form-item label="装运点" prop="shipmentPointNo">
            <el-input v-model="form.shipmentPointNo" disabled />
          </el-form-item>
          <el-form-item label="存储地点" prop="storeAddr">
            <el-input v-model="form.storeAddr" disabled />
          </el-form-item>
          <el-form-item label="批次号" prop="batchNo">
            <el-input v-model="form.batchNo" disabled />
          </el-form-item>
          <el-form-item label="实际交货日期" prop="actualDeliveryDate">
            <el-input
              v-model="form.actualDeliveryDate"
              value-format="yyyy-MM-dd"
              disabled
            >
            </el-input>
          </el-form-item>
          <el-form-item label="定价值" prop="pricingVal">
            <el-input v-model="form.pricingVal" disabled />
          </el-form-item>
          <el-form-item label="销售工厂" prop="saleFactory">
            <el-input v-model="form.saleFactory" disabled />
          </el-form-item>
          <el-form-item label="报价单位" prop="offerUnit">
            <el-input v-model="form.offerUnit" disabled />
          </el-form-item>
          <el-form-item label="销售单位" prop="saleUnit">
            <el-input v-model="form.saleUnit" disabled />
          </el-form-item>
          <el-form-item label="尺码单位" prop="sizeUnit">
            <el-input v-model="form.sizeUnit" disabled />
          </el-form-item>
          <el-form-item label="客户订单号" prop="poOrderNo">
            <el-input v-model="form.poOrderNo" disabled />
          </el-form-item>
          <el-form-item label="客户产品代码" prop="clientItemNo">
            <el-input v-model="form.clientItemNo" disabled />
          </el-form-item>
          <el-form-item label="客户产品名称" prop="clientItemName">
            <el-input v-model="form.clientItemName" disabled />
          </el-form-item>
          <el-form-item label="客户尺码单位" prop="clientSizeUnit">
            <el-input v-model="form.clientSizeUnit" disabled />
          </el-form-item>
          <el-form-item label="客户指令号" prop="clientCmd">
            <el-input v-model="form.clientCmd" disabled />
          </el-form-item>
          <el-form-item label="型体号" prop="typeNo">
            <el-input v-model="form.typeNo" disabled />
          </el-form-item>
          <el-form-item label="配色号" prop="colorNo">
            <el-input v-model="form.colorNo" disabled />
          </el-form-item>
          <el-form-item label="客户颜色" prop="color">
            <el-input v-model="form.color" disabled />
          </el-form-item>
          <el-form-item label="客户单重" prop="clientKg">
            <el-input v-model="form.clientKg" disabled />
          </el-form-item>
          <el-form-item label="销线" prop="salePath">
            <el-input v-model="form.salePath" disabled />
          </el-form-item>
          <el-form-item label="段别" prop="segment">
            <el-input v-model="form.segment" disabled />
          </el-form-item>
          <el-form-item label="版面" prop="layout">
            <el-input v-model="form.layout" disabled />
          </el-form-item>
          <el-form-item label="季度" prop="quarter">
            <el-input v-model="form.quarter" disabled />
          </el-form-item>
          <el-form-item label="整/半码" prop="wholeSize">
            <el-input v-model="form.wholeSize" disabled />
          </el-form-item>
          <el-form-item label="特殊尺码" prop="specSize">
            <el-input v-model="form.specSize" disabled />
          </el-form-item>
          <el-form-item label="po_no" prop="poNo">
            <el-input v-model="form.poNo" disabled />
          </el-form-item>
          <el-form-item label="wip_no" prop="wipNo">
            <el-input v-model="form.wipNo" disabled />
          </el-form-item>
          <el-form-item label="装箱数" prop="packingNum">
            <el-input v-model="form.packingNum" disabled />
          </el-form-item>
          <el-form-item label="周期" prop="cycle">
            <el-input v-model="form.cycle" disabled />
          </el-form-item>
          <el-form-item label="sk_no" prop="skNo">
            <el-input v-model="form.skNo" disabled />
          </el-form-item>
          <el-form-item label="专利号" prop="patentNo">
            <el-input v-model="form.patentNo" disabled />
          </el-form-item>
          <el-form-item label="材质描述" prop="materialDesc">
            <el-input v-model="form.materialDesc" disabled />
          </el-form-item>
          <el-form-item label="签收人" prop="signer">
            <el-input v-model="form.signer" disabled />
          </el-form-item>
          <el-form-item label="shipToId" prop="shipToId">
            <el-input v-model="form.shipToId" disabled />
          </el-form-item>
          <el-form-item label="交货日期" prop="deliveryDate">
            <el-input v-model="form.deliveryDate" disabled />
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" disabled />
          </el-form-item>
          <el-form-item label="尺码组" prop="sizeGroup">
            <el-input v-model="form.sizeGroup" disabled />
          </el-form-item>
          <el-form-item label="尺码" prop="size">
            <el-input v-model="form.size" disabled />
          </el-form-item>
          <el-form-item label="订单量" prop="orderNum">
            <el-input v-model="form.orderNum" disabled />
          </el-form-item>
          <el-form-item label="条码" prop="barCode">
            <el-input v-model="form.barCode" disabled />
          </el-form-item>
          <el-form-item label="印刷方向" prop="printingDirection">
            <el-input v-model="form.printingDirection" disabled />
          </el-form-item>
          <el-form-item label="产品规格" prop="prodSpec">
            <el-input v-model="form.prodSpec" disabled />
          </el-form-item>
          <el-form-item label="客户工厂代号" prop="plantCode">
            <el-input v-model="form.plantCode" disabled />
          </el-form-item>
          <el-form-item label="包装方式" prop="packMode">
            <el-input v-model="form.packMode" disabled />
          </el-form-item>
        </el-row>
      </el-form>

      <el-tabs type="border-card" @tab-click="tabClick">
        <el-tab-pane label="BOM">
          <ProogingBom ref="ProogingBomRef" />
        </el-tab-pane>
        <el-tab-pane label="工艺">
          <ProogingProcess ref="ProogingProcessRef" :bomList="bomList" />
        </el-tab-pane>
      </el-tabs>
    </PageWrapper>
    <RoutesProcessSelect
      ref="RoutesProcessSelectRef"
      @onSelected="onRoutesProcessSelect"
    />
    <ItemSelect ref="itemSelect" @onSelected="onItemSelected"> </ItemSelect>
  </div>
</template>

<script>
import { genCode } from "@/api/system/autocode/rule";
import ProogingBom from "./components/ProogingBom.vue";
import ProogingProcess from "./components/ProogingProcess.vue";
import ItemSelect from "@/components/itemSelect/single.vue";
import ClientSelect from "@/components/clientSelect/single.vue";
import VendorSelect from "@/components/vendorSelect/single.vue";
import RoutesProcessSelect from "@/components/routesProcessSelect/index.vue";
import { listRouteprocess } from "@/api/mes/pro/routeprocess";
import tabPlugins from "@/plugins/tab";
import {
  addPrototypeRequest,
  getPrototypeRequest,
  updatePrototypeRequest,
} from "@/api/mes/pro/prototypeRequest";
import {
  listWorkorder,
  getWorkorder,
  delWorkorder,
  addWorkorder,
  updateWorkorder,
  dofinish,
} from "@/api/mes/pro/workorder";
export default {
  components: {
    ProogingProcess,
    ProogingBom,
    ItemSelect,
    RoutesProcessSelect,
    ClientSelect,
    VendorSelect,
  },
  dicts: [
    "mes_workorder_status",
    "mes_workorder_sourcetype",
    "mes_workorder_type",
  ],
  provide() {
    return {
      mode: this.mode,
    };
  },
  data() {
    return {
      loading: false,
      optType: undefined,

      bomList: [],
      // 表单参数
      form: {
        workorderId: null,
        workorderCode: null,
        workorderName: null,
        routeName: null,
        workorderType: "SELF",
        orderSource: null,
        sourceCode: null,
        productId: null,
        productCode: null,
        productName: null,
        productSpc: null,
        unitOfMeasure: null,
        quantity: null,
        quantityProduced: null,
        quantityChanged: null,
        quantityScheduled: null,
        clientId: null,
        clientCode: null,
        clientName: null,
        vendorId: null,
        vendorCode: null,
        vendorName: null,
        requestDate: null,
        parentId: null,
        status: "PREPARE",
        orderId: null,
        orderNo: null,
        itemId: null,
        itemNo: null,
        sapItemNo: null,
        itemName: null,
        totalNum: null,
        num: null,
        lossNum: null,
        price: null,
        shipmentPointNo: null,
        storeAddr: null,
        batchNo: null,
        actualDeliveryDate: null,
        pricingVal: null,
        saleFactory: null,
        offerUnit: null,
        saleUnit: null,
        sizeUnit: null,
        poOrderNo: null,
        clientItemNo: null,
        clientItemName: null,
        clientSizeUnit: null,
        clientCmd: null,
        typeNo: null,
        colorNo: null,
        color: null,
        clientKg: null,
        salePath: null,
        segment: null,
        layout: null,
        quarter: null,
        wholeSize: null,
        specSize: null,
        poNo: null,
        wipNo: null,
        packingNum: null,
        cycle: null,
        skNo: null,
        patentNo: null,
        materialDesc: null,
        signer: null,
        shipToId: null,
        deliveryDate: null,
        sizeGroup: null,
        size: null,
        orderNum: null,
        barCode: null,
        printingDirection: null,
        prodSpec: null,
        plantCode: null,
        packMode: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      },
      // 表单校验
      rules: {
        workorderCode: [
          { required: true, message: "工单编码不能为空", trigger: "blur" },
        ],
        workorderName: [
          { required: true, message: "工单名称不能为空", trigger: "blur" },
        ],
        workorderType: [
          { required: true, message: "请选择生产工单类型", trigger: "blur" },
        ],
        orderSource: [
          { required: true, message: "来源类型不能为空", trigger: "blur" },
        ],
        productId: [
          { required: true, message: "产品不能为空", trigger: "blur" },
        ],
        productCode: [
          { required: true, message: "产品编号不能为空", trigger: "blur" },
        ],
        productName: [
          { required: true, message: "产品名称不能为空", trigger: "blur" },
        ],
        quantity: [
          { required: true, message: "生产数量不能为空", trigger: "blur" },
        ],
        requestDate: [
          { required: true, message: "需求日期不能为空", trigger: "blur" },
        ],
      },
    };
  },
  computed: {
    scrollHeight() {
      return "calc(100vh - 73px - 83px)";
    },
    mode() {
      return this.$route.path.split("/").at(-1);
    },
    pageTitle() {
      const titles = {
        edit: "工单修改",
        info: "工单新增",
        apply: "工单申请",
      };
      return titles[this.mode];
    },
  },
  created() {
    this.getFormInfo();
    if (this.mode == "apply") {
      this.gCode();
    }
  },

  methods: {
    /** 查询生产工单下拉树结构 */
    getTreeselect() {
      listWorkorder().then((response) => {
        this.workorderOptions = [];
        const data = {
          workorderId: 0,
          workorderName: "顶级节点",
          children: [],
        };
        data.children = this.handleTree(
          response.data,
          "workorderId",
          "parentId"
        );
        this.workorderOptions.push(data);
      });
    },
    /** 生成编码 */
    gCode() {
      genCode("WORKORDER_CODE").then((response) => {
        this.form.workorderCode = response;
      });
    },
    // //从BOM行中直接新增
    // handleSubAdd(row){
    //   this.open = false;
    //   this.reset();
    //   this.getTreeselect();
    //   if (row != null && row.workorderId) {
    //     this.form = row;
    //     this.form.parentId = row.workorderId;
    //     this.form.workorderId = null;
    //     this.form.workorderCode = null;
    //   } else {
    //     this.form.parentId = 0;
    //   }
    //   this.open = true;
    //   this.title = "添加生产工单";
    //   this.optType="add";
    // },

    //物料选择弹出框
    onItemSelected(obj) {
      if (obj != undefined && obj != null) {
        this.form.productId = obj.itemId;
        this.form.productCode = obj.itemCode;
        this.form.productName = obj.itemName;
        this.form.productSpc = obj.specification;
        this.form.unitOfMeasure = obj.unitOfMeasure;
      }
    },
    //客户选择弹出框

    onClientSelected(row) {
      if (row != undefined && row != null) {
        this.form.clientId = row.clientId;
        this.form.clientCode = row.clientCode;
        this.form.clientName = row.clientName;
      }
    },
    //供应商选择弹出框
    onVendorSelected(row) {
      debugger;
      if (row != undefined && row != null) {
        this.form.vendorId = row.vendorId;
        this.form.vendorCode = row.vendorCode;
        this.form.vendorName = row.vendorName;
      }
    },
    handleSelectProduct() {
      this.$refs.itemSelect.showFlag = true;
    },
    handleSelectClient() {
      this.$refs.clientSelect.showFlag = true;
    },

    handleSelectVendor() {
      this.$refs.vendorSelect.showFlag = true;
    },
    /** 根据 id 获取页面数据 */
    getFormInfo() {
      if (this.mode != "apply") {
        const id = this.$route.query.workorderId;
        this.loading = true;
        getWorkorder(id)
          .then(({ data }) => {
            Object.assign(this.form, data);
            this.bomList = data.bomList;
            // 设置组件数据
            this.$refs["ProogingBomRef"].tableData = data.bomList;
            this.$refs["ProogingProcessRef"].tableData = data.processList;
          })
          .finally(() => {
            this.loading = false;
          });
      }
    },
    // /** 生成编码 */
    // gCode() {
    //   genCode("PROTOTYPE_REQUEST_CODE").then((response) => {
    //     this.form.prototypeRequestCode = response;
    //   });
    // },
    /** 点击tab 获取bom的数据,将参数传递给后面的组件 */
    tabClick(val) {
      if (val.index != 0) {
        this.bomList = this.$refs["ProogingBomRef"].getComData();
      }
    },
    // onItemSelect(row) {
    //   if (row != undefined && row != null) {
    //     this.form.itemId = row.itemId;
    //     this.form.itemName = row.itemName;
    //     this.form.unit = row.unitOfMeasure;
    //   }
    // },
    //物料选择弹出框

    onRoutesProcessSelect(row) {
      if (row != undefined && row != null) {
        this.form.routeId = row.routeId;
        this.form.routeName = row.routeName;
        const params = {
          pageNum: 1,
          pageSize: 1000,
          routeId: row.routeId,
        };
        listRouteprocess(params).then(({ rows }) => {
          this.$refs["ProogingProcessRef"].setList(rows);
        });
      }
    },
    /**提交 */
    saveForm() {
      const bomList = this.$refs.ProogingBomRef.getComData();
      const processList = this.$refs.ProogingProcessRef.getComData();
      const params = {
        ...this.form,
        bomList,
        processList,
      };
      this.loading = true;
      if (this.mode == "apply") {
        addWorkorder(params)
          .then((res) => {
            this.loading = false;
            this.$modal.msgSuccess("提交成功！");

            this.$nextTick(() => {
              // 关闭页签
              tabPlugins.closeOpenPage();
              this.$router.replace({
                path: "/mes/pro/workorder",
              });
            });
          })
          .catch(() => {
            this.loading = false;
          });
      } else {
        updateWorkorder(params)
          .then(() => {
            this.loading = false;
            this.$modal.msgSuccess("提交成功！");
          })
          .catch(() => {
            this.loading = false;
          });
      }
    },
    /**重置表单 */
    resetForm() {
      this.form = {
        workorderId: null,
        workorderCode: null,
        workorderName: null,
        routeName: null,
        workorderType: "SELF",
        orderSource: null,
        sourceCode: null,
        productId: null,
        productCode: null,
        productName: null,
        productSpc: null,
        unitOfMeasure: null,
        quantity: null,
        quantityProduced: null,
        quantityChanged: null,
        quantityScheduled: null,
        clientId: null,
        clientCode: null,
        clientName: null,
        vendorId: null,
        vendorCode: null,
        vendorName: null,
        requestDate: null,
        parentId: null,
        status: "PREPARE",
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.$refs["ProogingBomRef"].resetState();
      this.$refs["ProogingProcessRef"].resetState();
      this.gCode();
    },
  },
};
</script>

<style lang="scss" scoped></style>
