<template>
    <!-- 组装 -->
    <div class="app-container">
      <el-form ref="form" :model="form" label-width="80px" align="center">
        <el-form-item label="任务号:" :label-width="'90px'">
          <el-input v-model="form.taskNumber" readonly disabled></el-input>
        </el-form-item>
        <el-form-item label="投产数量:" :label-width="'90px'">
          <el-input v-model="form.productQuantity" readonly disabled></el-input>
        </el-form-item>
        <el-form-item label="已组装数量"  :label-width="'90px'">
          <el-input v-model="form.assembled" readonly disabled></el-input>
        </el-form-item>
        <!--记录信息-->
<!--        <el-form-item>-->
<!--          <el-button-->
<!--            type="primary"-->
<!--            class="btn"-->
<!--            @click="submitHandler"-->
<!--            style="margin-left:-500px"-->
<!--          >记录信息</el-button-->
<!--          >-->
<!--        </el-form-item>-->
      </el-form>
    </div>
</template>

<script>
import { submitNodeForm } from "@/api/bpmprocess/runDialogApi/index";
export default {
    name: 'Assemble',
    props: ["formData", "row"],
    data() {
        return {
            isEdit: false,
            form: {
              taskNumber: '',
              productQuantity: '',
              assembled: '',
            }
        };
    },
    computed: {
        myFormData() {
            return this.formData;
        },
    },
    watch: {
        myFormData: {
            handler(nval) {
                this.form = nval.resultMap;
                this.isEdit = this.form.taskProcessKey && this.form.taskNodeKey;
                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 = {};
                let { teamId } = this.form;
                if (this.isEdit) {
                let { taskProcessKey, taskNodeKey } = this.myFormData.resultMap;
                payLoad.updateCommonEntityList = [
                    {
                    basicMap: {
                        tableName: "product_assembly",
                    },
                    conditionMap: {
                        task_process_key: taskProcessKey,
                        task_node_key: taskNodeKey,
                    },
                    commMap: {
                        team_id: teamId,
                        task_id: this.row.bepTaskPlanKey,
                    },
                    },
                ];
                } else {
                  console.log("新增")
                payLoad.insertCommonEntityList = [
                    {
                    basicMap: {
                        tableName: "product_assembly",
                    },
                    addListMap: [
                        {
                          taskNumber: this.form.taskNumber,
                          taskQuantity:this.form.productQuantity,
                          overNumber:this.form.assembled,
                          taskProcessKey: this.row.benTaskProcessKey,
                          taskNodeKey: this.row.benTaskNodeKey,
                        },
                    ],
                    },
                ];
                }
                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>
