<template>
    <!-- 检测 -->
    <div class="app-container">
        <el-form ref="form" :model="form" label-width="120px">
            <el-form-item label="任务号:">
              <el-input v-model="form.taskNumber" readonly disabled></el-input>
            </el-form-item>
            <el-form-item label="投产数量:">
              <el-input v-model="form.productQuantity" readonly disabled></el-input>
            </el-form-item>
            <el-form-item label="组装数量:">
              <el-input v-model="form.assembled" readonly disabled></el-input>
            </el-form-item>
            <el-form-item label="合格数量:">
              <el-input v-model="form.qualified"  readonly disabled></el-input>
            </el-form-item>
            <el-form-item label="不合格数量:">
              <el-input v-model="form.unqualified"  readonly disabled></el-input>
            </el-form-item>
              <!--记录信息-->
<!--              <el-form-item>-->
<!--                <el-button-->
<!--                  type="primary"-->
<!--                  class="btn"-->
<!--                  @click="submitHandler"-->
<!--                  style=""-->
<!--                >质检信息记录</el-button-->
<!--                >-->
<!--              </el-form-item>-->
        </el-form>
    </div>
</template>

<script>
import { submitNodeForm } from "@/api/bpmprocess/runDialogApi/index";
export default {
    name: 'Detection',
    props: ["formData", "row"],
    data() {
        return {
            isEdit: false,
            form: {
              taskNumber: '',
                productQuantity: '',
                assembled: '',
                qualified: '',
                unqualified: ''
            }
        };
    },
    computed: {
        myFormData() {
            return this.formData;
        },
    },
    watch: {
        myFormData: {
            handler(nval) {
                this.form = nval.resultMap;
              console.log(this.form,"ddddd")
                this.isEdit = this.form.taskProcessKey&&this.form.taskNodeKey;
               console.log(this.isEdit,"acd")
                this.$nextTick(() => {
                      this.$refs.form?.clearValidate();
                });
            },
            deep: true,
            immediate: true,
        },
    },
    mounted() {

    },

    methods: {
        async submitHandler() {
            console.log(this.row);
            let res = await this.$refs.form?.validate();
            if (res) {
                let payLoad = {};
                if (this.isEdit) {
                      console.log("修改")
                      let { taskProcessKey, taskNodeKey } = this.myFormData.resultMap;
                      payLoad.updateCommonEntityList = [
                          {
                          basicMap: {
                              tableName: "quality_inspection",
                          },
                          conditionMap: {
                              task_process_key: taskProcessKey,
                              task_node_key: taskNodeKey,
                          },
                          commMap: {
                            qualifiedQuantity:this.form.qualifiedNum,
                            unqualifiedQuantity:this.form.unqualifiedQuantity
                          },
                          },
                      ];
                } else {
                  console.log("新增")
                      payLoad.insertCommonEntityList = [
                          {
                          basicMap: {
                              tableName: "quality_inspection",
                          },
                          addListMap: [
                              {
                                taskNumber: this.form.taskNumber,
                                taskQuantity:this.form.productQuantity,
                                overNumber:this.form.assembled,
                                taskProcessKey: this.row.benTaskProcessKey,
                                taskNodeKey: this.row.benTaskNodeKey,
                                qualifiedQuantity:this.form.qualified,
                                unqualifiedQuantity:this.form.unqualified
                              },
                          ],
                          },
                      ];
                }
                submitNodeForm(payLoad).then((response) => {
                if (response.code == 200) {
                    this.$modal.msgSuccess("保存成功");
                } else {
                    this.$modal.error("保存失败,请稍后再试");
                }
                });
            }
        },
        async getFormData() {
            let formData = {
                flag: false,
                msg: "",
            };
            try {
                let valid = await this.$refs.form.validate();
                if (valid) {
                    formData.flag = true;
                    formData.data = this.form;
                    return formData;
                } else {
                    formData.msg = "表单校验异常,请规范填写表单数据";
                    return formData;
                }
            } catch (error) {
                // console.log(error);
                formData.msg = "表单校验异常,请规范填写表单数据";
                return formData;
            }
        },
    },
};
</script>

<style lang="scss" scoped>

</style>
