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

         <p style="color: orange;text-align: center">注：专票需要将所有开票资料填写完整</p>
        <a-form-item label="发票抬头" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'invoiceTitle', validatorRules.invoiceTitle]" :maxlength="100" placeholder="请输入发票抬头"></a-input>
        </a-form-item>

        <a-form-item label="纳税人识别号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dutyParagraph', validatorRules.dutyParagraph]" :maxlength="25" placeholder="请输入纳税人识别号"></a-input>
        </a-form-item>

        <a-form-item label="开户银行" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'accountBank', validatorRules.accountBank]" :maxlength="100" placeholder="请输入身份证号"></a-input>
        </a-form-item>


        <a-form-item label="开户账户" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'account', validatorRules.account]" :maxlength="25" placeholder="请输入开户账户" ></a-input>
        </a-form-item>


        <a-form-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'registerAddress', validatorRules.registerAddress]" :maxlength="100" placeholder="请输入地址"></a-input>
        </a-form-item>

        <a-form-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'registerPhone', validatorRules.registerPhone]" :maxlength="50" placeholder="请输入电话"></a-input>
        </a-form-item>

      </a-form>
    </a-spin>

  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import Vue from 'vue'
  import { ACCESS_TOKEN } from '@/store/mutation-types'

  export default {
    name: "HlwComapnyInvoiceInfoModal",
    components: {
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        bodyStyle: {
          paddingTop: '20px',
          paddingBottom:'20px',
          maxHeight: (window.innerHeight * 0.62) + 'px',
          'overflow-y': 'auto'
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        headers: {},
        uploadLoading: false,
        confirmLoading: false,
        validatorRules:{
          invoiceTitle:{rules: [{ required: true, message: '请输入发票抬头!' }]},
          dutyParagraph:{rules: [{ required: true, message: '请输入纳税人识别号!' }]},
          accountBank:{},
          account:{},
          registerAddress:{},
          registerPhone:{},
        },
        url: {
          add: "/saasmanager/hwPlatformCompany/companyInvoiceInfoAdd",
          edit: "/saasmanager/hwPlatformCompany/companyInvoiceInfoEdit",
        }

      }
    },
    created () {

    },
    computed: {

    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'invoiceTitle','dutyParagraph','accountBank','account','registerAddress','registerPhone'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).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();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },






    }
  }
</script>
<style lang="less" scoped>
  .avatar-uploader > .ant-upload {
    width: 104px;
    height: 104px;
  }

  .ant-upload-select-picture-card i {
    font-size: 49px;
    color: #999;
  }

  .ant-upload-select-picture-card .ant-upload-text {
    margin-top: 8px;
    color: #666;
  }
</style>