<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="[ 'serviceRate', validatorRules.serviceRate]" :precision="2" style="width: 100%"
                          placeholder="请输入服务费率"></a-input-number>
        </a-form-item>

      </a-form>
    </a-spin>
    <!--    <div class="drawer-bootom-button" v-show="!disableSubmit">-->
    <!--      <a-button class="ant-btn" @click="handleCancel">取消</a-button>-->
    <!--      <a-button class="ant-btn ant-btn-primary" style="margin-left: 8px" @click="handleOk">确定</a-button>-->
    <!--    </div>-->
  </a-modal>
</template>

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

  export default {
    name: 'HlgAccountEditServiceRateModal',
    mixins: [JeecgListMixin],
    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: {
          edit: '/hlgaccount/hlgAccount/editFate'
        }

      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        console.log(record)
        this.model = Object.assign({}, record)
        this.visible = true
        this.serviceRate = record.serviceRate
        this.companyId = record.companyId
        this.subcontractorId = record.subcontractorId

        // this.loadData(1)
      },
      loadData(arg) {
        // if (!this.url.list) {
        //   this.$message.error('请设置url.list属性!')
        //   return
        // }
        // //加载数据 若传入参数1则加载第一页的内容
        // if (arg === 1) {
        //   this.ipagination.current = 1
        // }
        // var params = this.getQueryParams()//查询条件
        // params.companyId = this.companyId
        // this.loading = true
        // getAction(this.url.list, params).then((res) => {
        //   if (res.success) {
        //     this.dataSource = res.result.records
        //     this.ipagination.total = res.result.total
        //   }
        //   if (res.code === 510) {
        //     this.$message.warning(res.message)
        //   }
        //   this.loading = false
        // })
      },
      close() {
        // this.$emit('ok')
        this.visible = false
      },
      handleOk() {
        this.form.validateFields((err, values) => {
          if (!err) {
            this.confirmLoading = true
            postAction(this.url.edit, {
              serviceRate: values.serviceRate, companyId: this.companyId,
              subcontractorId: this.subcontractorId
            }).then(data => {
              if (data.code === 200) {
                this.$emit('ok', values.serviceRate)
                this.confirmLoading = false;
                this.$message.info(data.message)
                this.close()
              }
            }).catch(() => {

            })

          }
        })

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


    }
  }
</script>