<template>
  <el-dialog title="修改" append-to-body :modelValue="openShow" width="60%" @close="closeDialog">
    <el-form :model="formData" :rules="rules" ref="formRules" :label-width="120">
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="计划单号" prop="ypCode">
            <el-input v-model="formData.ypCode" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="生产单号" prop="yoCode">
            <el-input v-model="formData.yoCode" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="零件号" prop="partCode">
            <el-select v-model="formData.partCode" placeholder="请输入" disabled>
              <el-option label="零件1" value="1" />
              <el-option label="零件12" value="2" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="批次号" prop="batchNo">
            <el-input v-model="formData.batchNo" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="流转编号" prop="roamNo">
            <el-select v-model="formData.roamNo" placeholder="请输入">
              <el-option label="B090989" value="1" />
              <el-option label="B0909889898" value="2" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="下级B号" prop="roamNo">
            <el-input v-model="formData.roamNo" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="订单类型" prop="yieldType">
            <el-select v-model="formData.yieldType" placeholder="请选择">
              <el-option :value="1" label="热表订单" />
              <el-option :value="2" label="烧结订单" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品型号" prop="productType">
            <el-input v-model="formData.productType" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品名称" prop="productName">
            <el-input v-model="formData.productName" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工艺路线" prop="primaryCraft">
            <el-input v-model="formData.primaryCraft" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="镀种" prop="plate">
            <el-input v-model="formData.plate" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="生产标识" prop="productIdent">
            <el-select v-model="formData.productIdent" placeholder="请选择">
              <el-option :value="1" label="JI-JII" />
              <el-option :value="2" label="JIII" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="使用部门" prop="useDept">
            <el-input v-model="formData.useDept" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="数量" prop="ypQty">
            <el-input v-model="formData.ypQty" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="面积(d㎡)" prop="ypArea">
            <el-input v-model="formData.ypArea" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="需求交期" prop="demandDate">
            <el-date-picker
              v-model="formData.demandDate"
              placeholder="请选择"
              type="datetime"
              format="YYYY-MM-DD HH:mm:ss"
              value-format="YYYY-MM-DD HH:mm:ss"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="计划员" prop="planUser">
            <el-input v-model="formData.planUser" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="计划下达时间" prop="releaseDate">
            <el-date-picker
              v-model="formData.releaseDate"
              placeholder="请选择"
              type="datetime"
              format="YYYY-MM-DD HH:mm:ss"
              value-format="YYYY-MM-DD HH:mm:ss"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="memo">
            <el-input
              v-model="formData.memo"
              :rows="2"
              type="textarea"
              minlength="0"
              maxlength="200"
              show-word-limit
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script>
import { update } from '@/api/orderManagement/planYieIdOrder';
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false,
    },
    moldAddMore: {
      type: Boolean,
      default: false,
    },
    id: {
      type: String,
      default: false,
    },
  },
  data() {
    return {
      openShow: false,
      tableData: [],
      formData: {},
      rules: {
        ypCode: [{ required: true, message: '请输入', trigger: 'blur' }],
        yoCode: [
          { required: true, message: '请输入', trigger: 'blur' },
          // { validator: checkYoCode, trigger: 'blur' },
        ],
        partCode: [{ required: true, message: '请输入', trigger: 'blur' }],
        productIdent: [{ required: true, message: '请输入', trigger: 'blur' }],
        useDept: [{ required: true, message: '请输入', trigger: 'blur' }],
        ypQty: [{ required: true, message: '请输入', trigger: 'blur' }],
        demandDate: [{ required: true, message: '请输入', trigger: 'blur' }],
        planUser: [{ required: true, message: '请输入', trigger: 'blur' }],
        releaseDate: [{ required: true, message: '请输入', trigger: 'blur' }],

        batchNo: [{ required: true, message: '请输入', trigger: 'blur' }],
        cardNo: [{ required: true, message: '请输入', trigger: 'blur' }],
        roamNo: [{ required: true, message: '请输入', trigger: 'blur' }],
        yieldType: [{ required: true, message: '请输入', trigger: 'blur' }],
      },
    };
  },
  mounted() {
    this.openShow = this.showDialog;
    this.formData = {
      partCode: 1,
      yoCode: 'WO-98978789988',
      batchNo: 'Y0232511359',
      businessType: -1,
      businessTypeTitle: null,
      cardNo: '1022413231',
      craftId: null,
      curStatus: 0,
      curStatusTitle: '待接收',
      custodian: '肖盼盼',
      demandDate: '2025-11-18',
      dsCraft: { craftId: 59361, craftNo: 'C000000' },
      dsPart: { partCode: '21E8-900-363-H1', partCode: 1, partName: 'M2 螺钉' },
      entrustDept: '采购与物流中心 (成件)',
      failureMan: {
        accountId: null,
        card: null,
        createTime: null,
        curStatus: 1,
        deleted: false,
        deptName: null,
      },
      failureMemo: null,
      failureTime: null,
      fatherVoid: null,
      keyValue: 4490279,
      kitPreparationMan: {
        accountId: null,
        card: null,
        createTime: null,
        curStatus: 1,
        deleted: false,
        deptName: null,
      },
      kitPreparationTime: null,
      manualIncrease: false,
      memo: null,
      newlevFlag: '采购',
      nextRoom: null,
      nextRoomName: null,
      partCode: '21E8-900-363-H1',
      partName: 'M2 螺钉',
      pdmUrl: null,
      pkDate: null,
      pkUsername: null,
      planUser: '申强',
      plate: 'Ct.P',
      ypArea: 0.0170467129,
      ypCode: 'WO-N251174111',
      poMemo: 'DZ',
      poProdLine: 'J303',
      ypQty: 22,
      primaryCraft: '库 1-1 (机加)-4 (表)- 库 2',
      priority: 1,
      prodident: 'JII',
      produceBool: false,
      productType: null,
    };
  },
  methods: {
    closeDialog() {
      this.openShow = false;
      this.$emit('closeDialog');
    },
    submit() {
      this.$refs.formRules.validate(valid => {
        if (valid) {
          update(this.formData).then(res => {
            console.log(res);
            if(res.code===200){
              this.openShow = false;
              this.$emit("closeDialog",true)
 
            }
          });
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped></style>
