<template>
  <a-modal
    centered
    class="fundAount-basicInfo-modal"
    :footer="null"
    :maskClosable="false"
    :title="'确认'+title"
    v-model="isShow"
    @cancel="isShow=false"
    :width="600">
    <a-spin :spinning="spinning" tip="Loading...">
      <a-form-model
        id="fundAount-basicInfo-form"
        ref="ruleForm"
        :model="form"
        :rules="rules"
        :label-col="formItemLayout.labelCol"
        :wrapper-col="formItemLayout.wrapperCol" >
        <a-form-model-item label="商户名称" style="margin-bottom: 0;" v-if="baseData&&baseData.settleClientName">
          <span class="ant-form-text">
            {{ baseData.settleClientName }}
          </span>
        </a-form-model-item>
        <a-form-model-item style="margin-bottom: 10px;" :label="title+'金额'" v-if="baseData">
          <span class="ant-form-text">
            {{ toThousands(baseData.totalAmount) }}
          </span>
        </a-form-model-item>
        <a-form-model-item label="结算方式" prop="settleStyleSn">
          <v-select
            code="SETTLE_STYLE"
            id="expenseManagementEdit-settleStyleSn"
            v-model="form.settleStyleSn"
            allowClear
            placeholder="请选择结算方式"
          ></v-select>
        </a-form-model-item>
        <a-form-model-item label="结算账户" prop="settleAccountSn">
          <settleAccount
            id="expenseManagementEdit-settleAccountSn"
            ref="settleAcount"
            v-model="form.settleAccountSn"
            :settleStyleSn="form.settleStyleSn"
            placeholder="请选择结算账户">
          </settleAccount>
        </a-form-model-item>
        <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
          <a-button type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
          <a-button @click="isShow=false" style="margin-left: 15px" id="chooseCustom-btn-back">取消</a-button>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { VSelect } from '@/components'
import { commonMixin } from '@/utils/mixin'
import settleAccount from '@/views/common/settleAccount'
export default {
  name: 'SettleModal',
  components: { settleAccount, VSelect },
  mixins: [commonMixin],
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      spinning: false,
      confirmLoading: false,
      isShow: this.openModal, //  是否打开弹框
      title: '确认',
      formItemLayout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 18 }
      },
      form: {
        settleStyleSn: '',
        settleStyleName: '',
        settleAccountSn: ''
      },
      rules: {
        settleStyleSn: [
          { required: true, message: '请选择结算方式', trigger: 'change' }
        ],
        settleAccountSn: [{ required: true, message: '请选择结算账户', trigger: 'change' }]
      },
      baseData: null
    }
  },
  methods: {
    resetForm () {
      this.$refs.ruleForm.resetFields()
      this.form = {
        settleStyleSn: '',
        settleStyleName: '',
        settleAccountSn: ''
      }
    },
    settleStyleChange (v, name) {
      this.form.settleStyleName = name.dispName
      if (this.form.settleAccountSn) {
        this.form.settleAccountSn = undefined
      }
    },
    //  保存
    handleSubmit (e) {
      e.preventDefault()
      const _this = this
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          _this.isShow = false
          _this.$emit('ok', this.form, this.baseData)
        } else {
          return false
        }
      })
    },
    // 编辑信息
    setData (data) {
      this.title = data.title
      this.baseData = data
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.resetForm()
      }
    }
  }
}
</script>

<style lang="less">
  .fundAount-basicInfo-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .radio-s{
      margin-bottom: 8px;
    }
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
  }
</style>
