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

        <a-form-item label="支付类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select type="list" v-decorator="['paymentType',validatorRules.paymentType]" :trigger-change="true" @change="changePaymentType"
                             :options="selectOption.options" placeholder="请选择支付类型" style="width: 100%"/>
        </a-form-item>


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

<script>

  import { httpAction,getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { duplicateCheck } from '@/api/api'
  const getApplicationSetting = (params) => getAction('/hlgcompany/hlgCompany/getApplicationSetting', params)
  
  export default {
    name: "HlgCompanySelectPaymentType",
    components: { 
    },
    data () {
      return {
        selectOption: {
          options: [

          ]
        },
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
          paymentType:{rules: [{ required: true, message: '请选择支付类型!' }]},
        },
        url: {
          edit: "/hlgcompany/hlgCompany/saveConfig",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.selectOption.options=[]
        getApplicationSetting({}).then((res) => {
          if (res.success) {
            if(res.message!=null){
              if(res.message.indexOf("0")!=-1){
                 this.selectOption.options.push({label: '应付', value: '0'})
              }
              if(res.message.indexOf("1")!=-1){
                this.selectOption.options.push({label: '实付', value: '1'})
              }
            }
          }
        })
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'paymentType','id'))
        })
      },
      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 = '';
            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()
      },
      changePaymentType(val){
        this.model.paymentType=val
          console.log(11111,val)
      }


    }
  }
</script>