<!-- 修改预计笔数 -->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible"
                 :editModel="editModel"
                 :form="modifyForm"
                 width="30%"
                 :autoSave="autoSave"
                 :formRules="formRules"
                  @onSaved="onSaved"
                 :title="$t('coordManageMain.planSampleCount')"
                 :appendToBody="appendToBody">
      <dym-form :componentList="componentList" :formValue="modifyForm"></dym-form>
    </dialog-edit>
  </div>
</template>

<script>
import { DialogEdit, dymForm } from 'newepoch-components'
import issueInput from '@/components/element/assetaudit/issueInput'
import coordManageApi from '@/api/assetoutfeedback/coordManage/coordManageApi'
import BasePage from '@/pages/baseEditPage'
export default {
  extends: new BasePage(),
  components: {
    DialogEdit, dymForm, issueInput
  },
  computed: {
    trcApi () {
      return coordManageApi.getTrclistSample
    }
  },
  props: {
    form: {
      type: Object,
      default () {
        return {}
      }
    },
    editModel: {
      type: String,
      default () {
        return 'E'
      }
    }
  },
  data () {
    return {
      autoSave: false,
      modifyForm: {
        planSampleCount: null
      },
      appendToBody: true,
      componentList: [
        {
          // 预计抽样笔数
          value: 'planSampleCount',
          maxlength: 19,
          componentName: issueInput,
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.planSampleCount,
          labelWidth: '120px',
          name: 'planSampleCount',
          cols: [16, 16, 16, 16],
          prop: 'planSampleCount'
        }
      ],
      formRules: {
        planSampleCount: [{
          required: true,
          message: this.$i18n.messages[this.$i18n.locale].coordManageMain.planSampleCount + this.$i18n.messages[this.$i18n.locale].feedbackMaterialIndex.null,
          trigger: 'change'
        }]
      }
    }
  },
  methods: {
    // 保存
    onSaved () {
      this.assetpkgmgrFullScreenLoading()
      this.trcApi.putDefaultCount({ keyId: this.form.keyId, planSampleCount: this.modifyForm.planSampleCount }).then(res => {
        this.assetpkgmgrFullScreenLoading().close()
        if (res.data) {
          this.success('预计抽样笔数修改成功')
          this.dialogVisible = false
          this.$emit('modifyNumber', this.modifyForm.planSampleCount)
        } else {
          this.error('预计抽样笔数修改失败')
        }
      }).catch(res => this.assetpkgmgrFullScreenLoading().close())
    }
  }
}
</script>

<style>

</style>
