<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 :min="0.01" :max="99.99" v-decorator="[ 'serviceRate', validatorRules.serviceRate]"
                          :formatter="value => `${value}%`" :parser="value => value.replace('%', '')" :precision="2"
                          placeholder="请输入服务费率"
                          style="width: 100%"/>
        </a-form-item>

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

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

  export default {
    name: 'HlgCpAccountEditServiceRateModal',
    mixins: [],
    components: {
      JDate
    },
    data() {
      return {
        title: '',
        bodyStyle: {
          paddingTop: '20px',
          paddingBottom:'20px',
          // 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: {
          serviceRate: {
            rules: [{ required: true, message: '请输入服务费率!' }, {
              validator: this.checkServiceRate
            }]
          }
        },
        confirmLoading: false,
        companyId: 0,
        url: {

        }

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

      close() {
        // this.$emit('ok')
        this.visible = false
      },
      handleOk() {
        this.form.validateFields((err, values) => {
          if (!err) {
            this.$emit('ok', values.serviceRate)
            this.close()
          }
        })

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


    }
  }
</script>