<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="结算总金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalMoneyName">
              <a-input v-model="model.totalMoneyName" placeholder="请输入结算总金额" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="balanceDate">
              <a-date-picker
                v-model="model.balanceDate"
                placeholder="请输入结算日期"
                format="YYYY-MM-DD HH:mm:ss"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                :showTime="true"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="balanceWay">
              <a-select v-model="model.balanceWay" placeholder="请选择结算方式" style="width: 100%">
                <a-select-option value="转账">转账</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="银行卡" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankCard">
              <a-input v-model="model.bankCard" placeholder="请输入银行卡"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remarks">
              <a-textarea placeholder="请输入备注" v-model="model.remarks" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  export default {
    name: 'PropertyAdvForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          totalMoneyName: [{ required: true, message: '请输入结算总金额', trigger: 'blur' }],
          balanceDate: [{ required: true, message: '请输入结算日期', trigger: 'change' }],
          balanceWay: [{ required: true, message: '请选择结算方式', trigger: 'change' }],
          bankCard: [{ required: true, message: '请输入银行卡', trigger: 'blur' }]
        },
        url: {
          add: "/property-central/partners/shareBalance/add"
        },
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({
          balanceDate: '',
          balanceWay: '转账',
          bankCard: '',
          remarks: ''
        }, record, {totalMoneyName: `¥${record.balanceMoney}`});
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            httpAction(this.url.add, {...this.model, balanceStatus: '2'}, 'post').then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>