CanZhuangJianEdit.vue 2.95 KB
/**
* @Description:
* @author wx
* @date 2021/04/28
*/
<template>
  <div class="canzhuangjian-edit">
    <dee-form
      :form="propForm"
      :form-data="propFormData"
      :form-buttons="formButtons"
      form-btn-position="center"
      @on-submit="submit"
      @on-cancel="cancel"
    />
  </div>
</template>

<script>
import { editCanZhuangJian } from '@/api/craft'
export default {
  name: 'CanZhuangJianEdit',
  components: {},
  props: {
    obj: {
      type: Object,
      default: () => {
      }
    },
    pageData: {
      type: Object,
      default: () => {
      }
    },
    item: {
      type: Object,
      default: () => {}
    },
    dialogShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      propForm: {},
      formButtons: [
        {
          'text': '确定',
          'type': 'submit',
          'component': {
            'type': 'primary'
          }
        },
        {
          'text': '取消',
          'type': 'cancel',
          'component': {
          }
        }
      ],
      units: []
    }
  },
  computed: {
    propFormData() {
      return [
        {
          title: '',
          split: 2,
          data: [{
            width: 1,
            key: 'amount',
            title: '数量',
            component: {
              name: 'el-input',
              size: 'middle'
            }
          },
          {
            key: 'unitCode',
            title: '单位 ',
            component: {
              name: 'el-select',
              options: this.units,
              size: 'middle'
            }
          }]
        }
      ]
    }
  },
  watch: {
    'propForm.amount'(val) {
      this.propForm.amount = val ? val.replace(/[^\d|.]/g, '') : ''
    },
    dialogShow: {
      immediate: true,
      deep: true,
      handler: function(flag) {
        if (flag) {
          const val = this.item
          if (val) {
            this.propForm = { id: val.id, amount: val.amount, unitCode: val.unitCode }
          }
        }
      }
    }
  },
  created() {
    this.getUnits()
  },
  mounted() {
  },
  methods: {
    async getUnits() {
      this.units = this.$store.state.dictionaries && this.$store.state.dictionaries.PartUnit ? this.$store.state.dictionaries.PartUnit.default : await this.$utils.getDicListByCode('PartUnit')
    },
    show() {
      this.dialogShow = true
    },
    submit() {
      const params = {
        operator: 'NO_CHANGE',
        id: this.pageData.id,
        sourceDxProcessPartLink: [{
          operator: 'MODIFY',
          id: this.propForm.id,
          amount: this.propForm.amount || null,
          unitCode: this.propForm.unitCode || null
        }]
      }
      editCanZhuangJian(params).then(res => {
        this.cancel()
        this.$utils.showMessageSuccess('添加成功!')
        this.obj.getTableData()
      }).catch(e => {
      })
    },
    cancel() {
      this.propForm = {}
      this.$emit('close')
    }
  }
}
</script>
<style lang='scss'>

</style>