<!-- 编辑备注 -->
<template>
  <div>
    <dialog-edit :appendToBody="appendToBody" width="45%" :visible.sync="dialogVisible" :editModel="editModel" :form="memoForm" :title="$t('effectDealFeedBackMain.editorialRemarks')" :formRules="formRules" :autoSave="autoSave" @onSaved="onSaved">
      <div class="memo-box">
        <el-form class="editFormMemo" :rules="formRules" :model="memoForm" label-position="top">
          <el-form-item prop="memo" :label="this.$i18n.messages[this.$i18n.locale].expressDataList.remark">
            <el-input type="textarea" :placeholder="$t('effectDealFeedBackMain.inputMemo')" :autosize="{ minRows: 4}" v-model="memoForm.memo"></el-input>
          </el-form-item>
        </el-form>
        <dym-form :componentList="componentList" :formValue.sync="memoForm"></dym-form>
      </div>
    </dialog-edit>
  </div>
</template>

<script>
import effectDealFeedBackApi from '@/api/assetoutfeedback/effectDealFeedBack/effectDealFeedBackApi'
import yesAndNoRadio from '@/pages/assetoutfeedback/effectDealFeedBack/effectDealFeedBackCom/yesAndNoRadio'
import overtRadio from '@/pages/assetoutfeedback/effectDealFeedBack/effectDealFeedBackCom/overtRadio'
import { DialogEdit, dymForm } from 'newepoch-components'
import BasePage from '@/pages/baseEditPage'
export default {
  extends: new BasePage(),
  components: { DialogEdit, dymForm, yesAndNoRadio, overtRadio },
  props: {
    form: {
      type: Object,
      default () {
        return {}
      }
    },
    editModel: {
      type: String,
      default () {
        return ''
      }
    },
    otherApi: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  computed: {
    // 编辑备注
    memoApi () {
      return effectDealFeedBackApi.getMemoInfo
    },
    memoForms () {
      let form = this.UtilJs.cloneDeep(this.memoForm)
      // this.form.identityFlag === '3'
      let name = ['effectMemo', 'chargeUserMemo', 'busyMemo'][this.form.identityFlag - 1]
      form[name] = this.memoForm.memo
      delete form.memo
      return form
    }
  },
  data () {
    return {
      memoForm: {},
      appendToBody: true,
      autoSave: false,
      formRules: {
        memo: [{
          required: true,
          message: this.$i18n.messages[this.$i18n.locale].expressDataList.remark + this.$i18n.messages[this.$i18n.locale].feedbackMaterialIndex.null,
          trigger: 'blur'
        }]
      },
      componentList: [
        {
          // 是否有退单风险
          value: 'chargebackRiskFlag',
          disabled: true,
          showFlag: true,
          componentName: yesAndNoRadio,
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.chargebackRiskFlagY,
          labelWidth: '110px',
          name: 'chargebackRiskFlag',
          cols: [24, 24, 24, 24],
          prop: 'chargebackRiskFlag'
        }, {
          // 是否公开
          value: 'openFlag',
          disabled: true,
          showFlag: true,
          componentName: overtRadio,
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.openFlag,
          labelWidth: '110px',
          name: 'openFlag',
          cols: [24, 24, 24, 24],
          prop: 'openFlag'
        }
      ]
    }
  },
  created () {
    if (this.form.identityFlag !== '1') {
      this.componentList[0].showFlag = false
      this.componentList[1].showFlag = false
    }
  },
  mounted () {
    if (this.form.identityFlag === '2') {
      this.$set(this.memoForm, 'chargeUserMemo', this.form.chargeUserMemo)
    } else if (this.form.identityFlag === '1') {
      this.$set(this.memoForm, 'effectMemo', this.form.effectMemo)
    } else {
      this.$set(this.memoForm, 'busyMemo', this.form.busyMemo)
    }
    this.memoForm = Object.assign({}, this.form)
    this.$set(this.memoForm, 'memo', this.form.effectMemo || this.form.chargeUserMemo || this.form.busyMemo)
  },
  methods: {
    onSaved () {
      let obj = this.UtilJs.isEmpty(this.otherApi) ? this.memoApi : this.otherApi
      if (!this.UtilJs.isEmpty(this.memoForm.memo)) {
        if (this.memoForm.memo.length < 1001) {
          this.assetpkgmgrFullScreenLoading()
          obj.postDefaultUpdate(this.memoForms).then(res => {
            this.assetpkgmgrFullScreenLoading().close()
            if (res.data) {
              this.success('编辑备注信息成功')
              this.$emit('close', true)
              this.dialogVisible = false
            } else {
              this.error('编辑备注信息失败')
            }
          }).catch(res => { this.assetpkgmgrFullScreenLoading().close() })
        } else {
          this.warning(this.$t('common.inputMemo'))
          return false
        }
      } else {
        this.warning(this.$t('common.noMemo'))
        return false
      }
    }
  }

}
</script>

<style lang="scss">
.editFormMemo .el-form-item__label{
  line-height:14px!important;
  padding-top: 10px;
}
</style>
