<template>
  <div class="app-containeteamIdr">
    <el-form :model="form" ref="form" label-position="top" label-width="100px" align="left" :inline="false" size="normal">
      <el-form-item label="质控卡号:" prop="remark">
        <el-input v-model="form.remark"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" @click="submitHandler" icon="el-icon-success">记录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import { submitNodeForm } from "@/api/bpmprocess/runDialogApi/index";
  export default {
    name: 'EditQualityCard',
    props: ["formData", "row"],
    data() {
      return {
        isEdit:false,
        form: {
          remark: ''
        },
      };
    },
    computed: {
      myFormData() {
        return this.formData;
      },
    },
    watch: {
      myFormData: {
        handler(nval) {
          this.form = nval.resultMap;
          // this.form.hp = this.form.goodId
          console.log(this.form);
          // this.isEdit = this.form.id ? true : false;
          this.isEdit = this.form.taskProcessKey && this.form.taskNodeKey
        },
        deep: true,
        immediate: true,
      },
    },
    mounted() {

    },
    methods: {
      async submitHandler() {
        console.log(this.row);
        let res = await this.$refs.form?.validate();
        if (res) {
          let payLoad = {};
          let { remark } = this.form;
          if (this.isEdit) {
            let { taskProcessKey, taskNodeKey } = this.myFormData.resultMap;
            payLoad.updateCommonEntityList = [
              {
                basicMap: {
                  tableName: "record_quality_control_card",
                },
                conditionMap: {
                  task_process_key: taskProcessKey,
                  task_node_key: taskNodeKey,
                },
                commMap: {
                  task_id: this.row.bepTaskPlanKey,
                  remark: remark
                },
              },
            ];
          } else {
            payLoad.insertCommonEntityList = [
              {
                basicMap: {
                  tableName: "record_quality_control_card",
                },
                addListMap: [
                  {
                    task_id: this.row.bepTaskPlanKey,
                    remark: remark,
                    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>
  ::v-deep .el-button{
    background: rgb(123,213,195);
    border:  rgb(123,213,195);
    float: right;
  }
</style>
