<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :bodyStyle="bodyStyle"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="服务费" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number  v-decorator="[ 'serviceFee', validatorRules.serviceFee]"
                          placeholder="请输入服务费" :precision="2" :min="0"
                          style="width: 100%"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction, getAction, postAction,putAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: 'HlwPaymentEditServiceRateModal',
    mixins: [],
    components: {
      JDate
    },
    data() {
      return {
        title: '',
        bodyStyle: {
          paddingTop: '20px',
          paddingBottom:'30px',
          // height: (window.innerHeight * 0.62) + 'px',
          'overflow-y': 'auto'
        },
        width:600,
        modelStyle: {
          width: '50%',
          style: { top: '20px' },
          fullScreen: false
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        form: this.$form.createForm(this),
        disableSubmit: false,
        validatorRules: {
          serviceFee: {
            rules: [{ required: true, message: '请输入服务费!' }, {
              validator: this.checkServiceRate
            }]
          }
        },
        confirmLoading: false,
        companyId: 0,
        url: {
          edit: '/wisdom/hlwPayment/editServiceFee'
        }

      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        this.model = Object.assign({}, record)
        this.visible = true
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'serviceFee'))
        })
      },

      close() {
        this.visible = false
      },
      handleOk() {
        const that = this;
        that.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true
            let formData = Object.assign(this.model, values);
            let url = ''
            url = that.url.edit
            putAction(url,formData).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })

      },
      checkServiceRate(rule, value, callback) {
        const _number = Number(value)
        if (isNaN((_number))) {
          callback('格式错误')
        }
        callback()
      },
      handleCancel() {
        this.close()
      }


    }
  }
</script>