<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="800px"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules">
      <div>
        <span style="color: #a6d580">{{__('公司信息</span>
        ')}}
      </div>
      <br />
      <br />
      <el-row :gutter="20">
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('供应商编号')" prop="supplier_number">
              <el-input
                v-model="form.supplier_number"
                :placeholder="__('供应商编号')"
              />
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('供应商名称')" prop="supplier_name">
              <el-input
                v-model="form.supplier_name"
                :placeholder="__('供应商名称')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('供应商类别')" prop="supplier_type_id">
              <el-input
                v-model="form.supplier_type_id"
                :placeholder="__('供应商类别')"
              />
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('增值税率')" prop="supplier_tax_rate">
              <el-input
                v-model="form.supplier_tax_rate"
                :placeholder="__('增值税率')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('备注消息')" prop="supplier_remark">
              <el-input
                v-model="form.supplier_remark"
                :placeholder="__('备注消息')"
              />
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('开户银行')" prop="supplier_bank">
              <el-input
                v-model="form.supplier_bank"
                :placeholder="__('开户银行')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('银行账户')" prop="supplier_card">
              <el-input
                v-model="form.supplier_card"
                :placeholder="__('银行账户')"
              />
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('开户名称')" prop="supplier_account_name">
              <el-input
                v-model="form.supplier_account_name"
                :placeholder="__('开户名称')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('纳税人识别号')" prop="supplier_taxnum">
              <el-input
                v-model="form.supplier_taxnum"
                :placeholder="__('纳税人识别号')"
              />
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('发票抬头')" prop="supplier_invoice">
              <el-input
                v-model="form.supplier_invoice"
                :placeholder="__('发票抬头')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('店铺编号')" prop="supplier_taxnum">
              <el-input
                v-model="form.store_id"
                disabled
                :placeholder="__('店铺编号')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>

      <!--    </el-form>-->

      <!--    <el-form ref="formaccount" :model="formaccount" >-->
      <div>
        <span style="color: #a6d580">{{__('个人信息</span>
        ')}}
      </div>
      <br />
      <br />

      <el-row :gutter="20">
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('联系人')" prop="supplier_contacter_name">
              <el-input
                v-model="form.supplier_contacter_name"
                :placeholder="__('联系人')"
              />
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item
              :label="__('联系人Im/MSN/QQ')"
              prop="supplier_contacter_im"
            >
              <el-input
                v-model="form.supplier_contacter_im"
                :placeholder="__('联系人Im/MSN/QQ')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item
              :label="__('联系人手机')"
              prop="supplier_contacter_mobile"
            >
              <el-input
                v-model="form.supplier_contacter_mobile"
                :placeholder="__('联系人')"
              />
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item
              :label="__('联系人座机')"
              prop="supplier_contacter_telephone"
            >
              <el-input
                v-model="form.supplier_contacter_telephone"
                :placeholder="__('联系人座机')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item
              :label="__('联系人区域')"
              prop="supplier_contacter_district_ids"
            >
              <el-input
                v-model="form.supplier_contacter_district_ids"
                :placeholder="__('联系人区域')"
              />
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <el-form-item
              :label="__('联系人地址')"
              prop="supplier_contacter_address"
            >
              <el-input
                v-model="form.supplier_contacter_address"
                :placeholder="__('联系人地址')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item :label="__('邮编')" prop="supplier_contacter_code">
              <el-input
                v-model="form.supplier_contacter_code"
                :placeholder="__('邮编')"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">{{ __('取消') }}</el-button>
      <el-button type="primary" @click="save">{{ __('确定') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import { doEdit } from '@/api/supplier/base'
  // import { doEditcontacter } from '@/api/supplier/contacter'

  export default {
    name: 'SupplierBaseEdit',
    components: {},
    data() {
      return {
        form: {},
        // formaccount: {},
        rules: {},
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    mounted() {
      this.rules = {
        supplier_id: [
          { required: true, trigger: 'blur', message: this.__('供应商编号') },
        ],
        supplier_number: [
          { required: true, trigger: 'blur', message: this.__('供应商编号') },
        ],
        supplier_name: [
          { required: true, trigger: 'blur', message: this.__('供应商名称') },
        ],
        supplier_type_id: [
          { required: true, trigger: 'blur', message: this.__('供应商类别') },
        ],
        supplier_tax_rate: [
          { required: true, trigger: 'blur', message: this.__('增值税税率') },
        ],
        supplier_remark: [
          { required: true, trigger: 'blur', message: this.__('备注消息') },
        ],
        supplier_level_id: [
          { required: true, trigger: 'blur', message: this.__('') },
        ],
        supplier_bank: [
          { required: true, trigger: 'blur', message: this.__('开户银行') },
        ],
        supplier_card: [
          { required: true, trigger: 'blur', message: this.__('银行账号') },
        ],
        supplier_account_name: [
          { required: true, trigger: 'blur', message: this.__('开户名称') },
        ],
        supplier_taxnum: [
          { required: true, trigger: 'blur', message: this.__('纳税人识别号') },
        ],
        supplier_invoice: [
          { required: true, trigger: 'blur', message: this.__('发票抬头') },
        ],
        store_id: [
          { required: true, trigger: 'blur', message: this.__('店铺编号') },
        ],
      }

      this.$forceUpdate()
    },
    methods: {
      __,
      showEdit(row) {
        if (!row) {
          this.title = this.__('添加')
        } else {
          this.title = this.__('编辑')
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close() {
        this.form = this.$options.data().form
        this.$refs['form'].resetFields()
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg, status } = await doEdit(this.form)

            if (200 == status) {
              this.$baseMessage(msg, 'success')
            } else {
              this.$baseMessage(msg, 'error')
            }
            this.$emit('fetch-data')
            this.close()
          } else {
            return false
          }
        })
      },
    },
  }
</script>
