<!--
 * @Date: 2021-01-09 16:25:11
 * @LastEditors: guo
 * @LastEditTime: 2021-03-13 17:15:16
 * @FilePath: \basic-admin\src\views\QualityManager\plan\subpage\EditForm.vue
 * @Description: 设备配方添加参数
-->
<template>
  <div>
    <el-dialog v-bind="$attrs" :title="$t('module.quality.planDetail.addDialogTitle')" v-on="$listeners" @open="onOpen" @close="onClose">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="150px">
        <el-form-item :label="$t('module.quality.planDetail.name')" prop="name">
          <el-input v-model="formData.name" clearable :style="{width: '100%'}" />
        </el-form-item>
        <el-form-item :label="$t('module.quality.planDetail.references')" prop="references">
          <el-input v-model="formData.references" clearable :style="{width: '100%'}" />
        </el-form-item>
        <el-form-item :label="$t('module.quality.planDetail.remark')" prop="remark">
          <el-input v-model="formData.remark" clearable :style="{width: '100%'}" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">{{ 'btn.cancel' | i18nFilter }}</el-button>
        <el-button type="primary" @click="handelConfirm">{{ 'btn.confirm' | i18nFilter }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { editPlanParamInfo, getPlanParamInfo } from '@/api/quality-manage/plan'
import i18n from '@/lang'
export default {
  components: {},
  inheritAttrs: false,
  props: {
    targetInfo: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      formData: {
        name: undefined,
        inspectionPlanId: null,
        references: undefined,
        remark: undefined
      },
      rules: {
        name: [{
          required: true,
          message: i18n.t('module.quality.planDetail.notEmpty'),
          trigger: 'change'
        }],
        references: [{
          required: true,
          message: i18n.t('module.quality.planDetail.notEmpty'),
          trigger: 'blur'
        }],
        remark: []
      },
      dict: {
        param: []
      }
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onOpen() {
      this.formData.inspectionPlanId = this.targetInfo?.id
      this.getInfo()
    },
    onClose() {
      this.$refs['elForm'].resetFields()
    },
    close() {
      this.$emit('update:visible', false)
    },
    handelConfirm() {
      this.$refs['elForm'].validate(async valid => {
        if (!valid) return
        const result = await editPlanParamInfo(this.formData)
        if (result.code === 0) {
          this.$message({
            type: 'success',
            message: '添加成功！'
          })
          this.$emit('done')
          this.close()
        }
      })
    },
    async getInfo() {
      const result = await getPlanParamInfo({
        id: this.targetInfo?.id
      })
      if (result.code === 0) {
        this.formData = result.data
      }
    }
  }
}

</script>
<style>
</style>
