<template>
  <a-modal
    class="container"
    :visible="value"
    title="编辑渠道"
    width="60%"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-form
      :form="form"
      v-if="formData"
    >
      <a-form-item
        label="名称"
        v-bind="formItemLayout"
      >
        <a-input
          disabled
          v-decorator="[
            'channel_name',
            {
              initialValue:formData.channel_name,
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        label="渠道"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'invoice_seller',
            {
              initialValue:formData.invoice_seller,
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        label="商品编码"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'goods_code',
            {
              initialValue:formData.goods_code,
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        label="商品项目名称"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'goods_code_name',
            {
              initialValue:formData.goods_code_name,
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        label="纳税人识别号"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'mch_taxpayer_num',
            {
              initialValue:formData.mch_taxpayer_num,
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        label="税率"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'tax_num',
            {
              initialValue:formData.tax_num,
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        label="电话"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'phone',
            {
              initialValue:formData.phone,
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        label="地址"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'address',
            {
              initialValue:formData.address,
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        label="接口地址"
        v-bind="formItemLayout"
      >
        <a-input
          v-decorator="[
            'url',
            {
              initialValue:formData.url,
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
    </a-form>

  </a-modal>
</template>

<script>
import { invoiceUpdateChannel } from '@/api/ticketSetting/invoice'
import invoiceMixin from './invoiceMixin.js'

export default {
  mixins: [invoiceMixin],
  components: {
  },
  props: {
    formData: {
      type: Object,
      default: () => null
    }
  },
  data () {
    return {
    }
  },
  methods: {
    handleOk (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          invoiceUpdateChannel(values).then(res => {
            this.$message.success('修改成功。')
          })

          this.form.resetFields()
          this.$emit('input', false)

          // 数据更新有延迟
          setTimeout(() => {
            this.$emit('update')
          }, 500)
        }
      })
    }
  }
}
</script>

  <style scoped>
  .ant-form-item{
  width: 50%; display: inline-block;
}
  </style>
