<template>
  <dialog-edit :visible.sync="dialogVisible" :editModel="editModel" :form="formValue" :autoSave="false"
               :openPerms="true" savePerms="btnSave" :menuCode="menuCode"
               @onSaved="handleClick" :loading="loading"
               width="700px" :title="$t('economyLendingInfoList.clfkBtn')" :api="api" :formRules="formRules">
    <dym-form :componentList="componentList" :formValue.sync="formValue"></dym-form>
<!--    <template slot="footer">-->
<!--      <auth-button size="medium" type="primary" :label="$t('common.save')" @click="handleClick"></auth-button>-->
<!--      <auth-button size="medium" type="" :label="$t('common.close')" @click="dialogVisible = false"></auth-button>-->
<!--    </template>-->
  </dialog-edit>
</template>

<script>
import { dymForm, authButton, DialogEdit } from 'newepoch-components'
import BasePage from '@/pages/baseEditPage'
import economyLendingApi from '@/api/economyLendingApi'
import * as format from '@/filters/index'
export default {
  extends: new BasePage(),
  components: {
    DialogEdit,
    dymForm,
    authButton
  },
  props: {
    menuCode: {
      type: String,
      default: null
    }
  },
  mounted () {
  },
  computed: {
    api () {
      return economyLendingApi.economyLending
    }
  },
  data () {
    return {
      loading: false,
      componentList: [
        // 实际放款日期(供应商)
        {
          value: 'loanDateFactoring',
          disabled: false,
          componentName: 'el-date-picker',
          label: this.$i18n.messages[this.$i18n.locale].economyLendingInfoList.supplierActualLendingDate,
          labelWidth: '160px',
          cols: [24, 24, 24, 24],
          prop: 'loanDateFactoring'
        },
        // 实际放款日期(保理商)
        {
          value: 'loanDateBank',
          disabled: false,
          componentName: 'el-date-picker',
          label: this.$i18n.messages[this.$i18n.locale].economyLendingInfoList.factorActualLendingDate,
          labelWidth: '160px',
          cols: [24, 24, 24, 24],
          prop: 'loanDateBank'
        },
        // 处理意见
        {
          value: 'auditOpinions2',
          disabled: false,
          componentName: 'el-input',
          maxlength: 200,
          rows: 3,
          type: 'textarea',
          label: this.$i18n.messages[this.$i18n.locale].economyLendingInfoList.disposalOpinions,
          labelWidth: '160px',
          cols: [24, 24, 24, 24],
          prop: 'auditOpinions2'
        }
      ],
      formRules: {
        loanDateFactoring: [
          { required: true, message: this.$i18n.messages[this.$i18n.locale].economyLendingInfoList.supplierMsg, trigger: 'change' }
        ],
        loanDateBank: [
          { required: true, message: this.$i18n.messages[this.$i18n.locale].economyLendingInfoList.factorMsg, trigger: 'change' }
        ],
        auditOpinions2: [
          { required: true, message: this.$i18n.messages[this.$i18n.locale].economyLendingInfoList.handleSuggestionMsg, trigger: 'blur' }]
      },
      formValue: {}
    }
  },
  methods: {
    handleClick () {
      let $this = this
      let putForm = Object.assign({}, $this.formValue)
      console.log(putForm)
      putForm.auditType = '0'
      putForm.auditor = this.$store.state.user.user.userName
      putForm.auditorId = this.$store.state.user.user.userId
      putForm.auditOpinions = this.formValue.auditOpinions2
      // putForm.loanDateBank = (new Date(putForm.loanDateBank)).getTime()
      // putForm.loanDateFactoring = (new Date(putForm.loanDateFactoring)).getTime()
      this.loading = true
      economyLendingApi.economyLoanAudit.audit(putForm).then(res => {
        if (res && res.data) {
          $this.success(this.$i18n.messages[this.$i18n.locale].economyLendingInfoList.handleSuccessMsg)
          $this.$emit('audit-success')
          $this.dialogVisible = false
        } else {
          $this.error(this.$i18n.messages[this.$i18n.locale].economyLendingInfoList.handleFailMsg)
        }
      }).finally(() => {
        this.loading = false
      })
    }
  },
  watch: {
    dialogVisible (value) {
      if (value) {
        this.formValue = Object.assign({}, this.form)
        this.$set(this.formValue, 'loanDateFactoring', format.formatDateTpcModify(this.formValue.loanDateFactoring))
        this.$set(this.formValue, 'loanDateBank', format.formatDateTpcModify(this.formValue.loanDateBank))
      }
    }
  }
}
</script>

<style scoped>
</style>
