<!--区域专员备注-->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :title="$t('ladingManageList.areaCommissionerMemo')" width="800px" :api="api" :form="form"
                 :loading="saveLoading" :menuCode="menuCode" savePerms="showAreaCommissionerMemoSave" :openPerms="true"
                 :editModel="editModel" :formRules="formRules" @onSaved="save" :autoSave="false">
      <dym-form :formValue.sync="form" :componentList="componentList"></dym-form>
    </dialog-edit>
  </div>
</template>

<script>
import { DialogEdit, dymForm } from 'newepoch-components'
import BaseEditPage from '@/pages/baseEditPage'
import ladingManageApi from '@/api/ladingManageApi'
export default {
  extends: new BaseEditPage(''),
  components: {
    DialogEdit,
    dymForm
  },
  props: {
    rows: {
      type: Array,
      default: function () {
        return []
      }
    },
    menuCode: {
      type: String,
      default: null
    }
  },
  data () {
    return {
      saveLoading: false,
      formRules: {
        areaCommissionerMemo: [{
          required: true,
          message: this.$i18n.messages[this.$i18n.locale].ladingManageList.inputAreaCommissionerMemo,
          trigger: 'blur'
        }]
      },
      componentList: [
        // 区域专员备注
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.areaCommissionerMemo,
          labelWidth: '120px',
          value: 'areaCommissionerMemo',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 24],
          componentName: 'el-input',
          prop: 'areaCommissionerMemo',
          type: 'textarea',
          rows: 3,
          maxlength: 100
        }
      ]
    }
  },
  mounted () {
  },
  computed: {
    api: function () {
      return ladingManageApi.ladingManageList
    }
  },
  methods: {
    save () {
      this.saveLoading = true
      let parmas = []
      this.rows.forEach(it => {
        parmas.push({ coreAreaRemark: this.form.areaCommissionerMemo, keyId: it.keyId })
      })
      let $this = this
      ladingManageApi.ladingManageList.updateMemo(parmas).then(res => {
        if (res.success) {
          $this.success(this.$i18n.messages[this.$i18n.locale].common.saveSuccess)
          this.dialogVisible = false
          $this.$emit('refinish')
        } else {
          this.saveLoading = false
          $this.error(this.$i18n.messages[this.$i18n.locale].common.saveError)
        }
      }).catch(res => {
        this.saveLoading = false
      })
    }
  },
  watch: {
    dialogVisible (newVal) {
      if (newVal) {
        this.saveLoading = false
      } else {
      }
    }
  }
}
</script>
