<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="500px"
    @close="close"
  >
    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
      <el-form-item :label="__('支付流水号')" prop="deposit_id">
        <el-input v-model="form.deposit_id" :placeholder="__('支付流水号')" />
      </el-form-item>
      <el-form-item :label="__('商户网站唯一订单号')" prop="order_id">
        <el-input
          v-model="form.order_id"
          :placeholder="__('商户网站唯一订单号')"
        />
      </el-form-item>
      <el-form-item :label="__('交易号')" prop="deposit_trade_no">
        <el-input v-model="form.deposit_trade_no" :placeholder="__('交易号')" />
      </el-form-item>
      <el-form-item :label="__('支付渠道')" prop="payment_channel_id">
        <el-input
          v-model="form.payment_channel_id"
          :placeholder="__('支付渠道')"
        />
      </el-form-item>
      <el-form-item :label="__('订单来源')" prop="app_id">
        <el-input v-model="form.app_id" :placeholder="__('订单来源')" />
      </el-form-item>
      <el-form-item :label="__('服务器编号')" prop="server_id">
        <el-input v-model="form.server_id" :placeholder="__('服务器编号')" />
      </el-form-item>
      <el-form-item :label="__('支付渠道app_id')" prop="deposit_app_id_channel">
        <el-input
          v-model="form.deposit_app_id_channel"
          :placeholder="__('支付渠道app_id')"
        />
      </el-form-item>
      <el-form-item :label="__('商品名称')" prop="deposit_subject">
        <el-input
          v-model="form.deposit_subject"
          :placeholder="__('商品名称')"
        />
      </el-form-item>
      <el-form-item :label="__('支付方式')" prop="deposit_payment_type">
        <el-input
          v-model="form.deposit_payment_type"
          :placeholder="__('支付方式')"
        />
      </el-form-item>
      <el-form-item :label="__('交易状态')" prop="deposit_trade_status">
        <el-input
          v-model="form.deposit_trade_status"
          :placeholder="__('交易状态')"
        />
      </el-form-item>
      <el-form-item :label="__('卖家户号')" prop="deposit_seller_id">
        <el-input
          v-model="form.deposit_seller_id"
          :placeholder="__('卖家户号')"
        />
      </el-form-item>
      <el-form-item :label="__('卖家支付账号')" prop="deposit_seller_email">
        <el-input
          v-model="form.deposit_seller_email"
          :placeholder="__('卖家支付账号')"
        />
      </el-form-item>
      <el-form-item :label="__('买家支付用户号')" prop="deposit_buyer_id">
        <el-input
          v-model="form.deposit_buyer_id"
          :placeholder="__('买家支付用户号')"
        />
      </el-form-item>
      <el-form-item :label="__('买家支付宝账号')" prop="deposit_buyer_email">
        <el-input
          v-model="form.deposit_buyer_email"
          :placeholder="__('买家支付宝账号')"
        />
      </el-form-item>
      <el-form-item :label="__('货币编号')" prop="currency_id">
        <el-input v-model="form.currency_id" :placeholder="__('货币编号')" />
      </el-form-item>
      <el-form-item :label="__('左符号')" prop="currency_symbol_left">
        <el-input
          v-model="form.currency_symbol_left"
          :placeholder="__('左符号')"
        />
      </el-form-item>
      <el-form-item :label="__('交易金额')" prop="deposit_total_fee">
        <el-input
          v-model="form.deposit_total_fee"
          :placeholder="__('交易金额')"
        />
      </el-form-item>
      <el-form-item :label="__('购买数量')" prop="deposit_quantity">
        <el-input
          v-model="form.deposit_quantity"
          :placeholder="__('购买数量')"
        />
      </el-form-item>
      <el-form-item :label="__('商品单价')" prop="deposit_price">
        <el-input v-model="form.deposit_price" :placeholder="__('商品单价')" />
      </el-form-item>
      <el-form-item :label="__('商品描述')" prop="deposit_body">
        <el-input v-model="form.deposit_body" :placeholder="__('商品描述')" />
      </el-form-item>
      <el-form-item :label="__('交易创建时间')" prop="deposit_gmt_create">
        <el-input
          v-model="form.deposit_gmt_create"
          :placeholder="__('交易创建时间')"
        />
      </el-form-item>
      <el-form-item :label="__('交易付款时间')" prop="deposit_gmt_payment">
        <el-input
          v-model="form.deposit_gmt_payment"
          :placeholder="__('交易付款时间')"
        />
      </el-form-item>
      <el-form-item :label="__('')" prop="deposit_gmt_close">
        <el-input v-model="form.deposit_gmt_close" :placeholder="__('')" />
      </el-form-item>
      <el-form-item
        :label="__('是否调整总价')"
        prop="deposit_is_total_fee_adjust"
      >
        <el-input
          v-model="form.deposit_is_total_fee_adjust"
          :placeholder="__('是否调整总价')"
        />
      </el-form-item>
      <el-form-item :label="__('是否使用红包买家')" prop="deposit_use_coupon">
        <el-input
          v-model="form.deposit_use_coupon"
          :placeholder="__('是否使用红包买家')"
        />
      </el-form-item>
      <el-form-item :label="__('折扣')" prop="deposit_discount">
        <el-input v-model="form.deposit_discount" :placeholder="__('折扣')" />
      </el-form-item>
      <el-form-item :label="__('通知时间')" prop="deposit_notify_time">
        <el-input
          v-model="form.deposit_notify_time"
          :placeholder="__('通知时间')"
        />
      </el-form-item>
      <el-form-item :label="__('通知类型')" prop="deposit_notify_type">
        <el-input
          v-model="form.deposit_notify_type"
          :placeholder="__('通知类型')"
        />
      </el-form-item>
      <el-form-item :label="__('通知校验编号')" prop="deposit_notify_id">
        <el-input
          v-model="form.deposit_notify_id"
          :placeholder="__('通知校验编号')"
        />
      </el-form-item>
      <el-form-item :label="__('签名方式')" prop="deposit_sign_type">
        <el-input
          v-model="form.deposit_sign_type"
          :placeholder="__('签名方式')"
        />
      </el-form-item>
      <el-form-item :label="__('签名')" prop="deposit_sign">
        <el-input v-model="form.deposit_sign" :placeholder="__('签名')" />
      </el-form-item>
      <el-form-item :label="__('额外参数')" prop="deposit_extra_param">
        <el-input
          v-model="form.deposit_extra_param"
          :placeholder="__('额外参数')"
        />
      </el-form-item>
      <el-form-item :label="__('支付')" prop="deposit_service">
        <el-input v-model="form.deposit_service" :placeholder="__('支付')" />
      </el-form-item>
      <el-form-item :label="__('支付状态')" prop="deposit_state">
        <el-input v-model="form.deposit_state" :placeholder="__('支付状态')" />
      </el-form-item>
      <el-form-item :label="__('是否同步')" prop="deposit_async">
        <el-input v-model="form.deposit_async" :placeholder="__('是否同步')" />
      </el-form-item>
      <el-form-item :label="__('收款确认')" prop="deposit_review">
        <el-input v-model="form.deposit_review" :placeholder="__('收款确认')" />
      </el-form-item>
      <el-form-item :label="__('是否作废')" prop="deposit_enable">
        <el-input v-model="form.deposit_enable" :placeholder="__('是否作废')" />
      </el-form-item>
      <el-form-item :label="__('所属店铺')" prop="store_id">
        <el-input v-model="form.store_id" :placeholder="__('所属店铺')" />
      </el-form-item>
      <el-form-item :label="__('所属用户')" prop="user_id">
        <el-input v-model="form.user_id" :placeholder="__('所属用户')" />
      </el-form-item>
      <el-form-item :label="__('所属门店')" prop="chain_id">
        <el-input v-model="form.chain_id" :placeholder="__('所属门店')" />
      </el-form-item>
      <el-form-item :label="__('所属分站')" prop="subsite_id">
        <el-input v-model="form.subsite_id" :placeholder="__('所属分站')" />
      </el-form-item>
    </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 { mapActions, mapGetters } from 'vuex'
  import { translateTitle as __ } from '@/utils/i18n'

  import { doEdit } from '@/api/consume/deposit'

  export default {
    name: 'ConsumeDepositEdit',
    data() {
      return {
        form: {},
        rules: {},
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    mounted() {
      this.form = {
        unit_name: '',
      }

      this.rules = {
        deposit_id: [
          { required: true, trigger: 'blur', message: this.__('支付流水号') },
        ],
        order_id: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('商户网站唯一订单号'),
          },
        ],
        deposit_trade_no: [
          { required: true, trigger: 'blur', message: this.__('交易号') },
        ],
        payment_channel_id: [
          { required: true, trigger: 'blur', message: this.__('支付渠道') },
        ],
        app_id: [
          { required: true, trigger: 'blur', message: this.__('订单来源') },
        ],
        server_id: [
          { required: true, trigger: 'blur', message: this.__('服务器id') },
        ],
        deposit_app_id_channel: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('支付渠道app_id'),
          },
        ],
        deposit_subject: [
          { required: true, trigger: 'blur', message: this.__('商品名称') },
        ],
        deposit_payment_type: [
          { required: true, trigger: 'blur', message: this.__('支付方式') },
        ],
        deposit_trade_status: [
          { required: true, trigger: 'blur', message: this.__('交易状态') },
        ],
        deposit_seller_id: [
          { required: true, trigger: 'blur', message: this.__('卖家户号') },
        ],
        deposit_seller_email: [
          { required: true, trigger: 'blur', message: this.__('卖家支付账号') },
        ],
        deposit_buyer_id: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('买家支付用户号'),
          },
        ],
        deposit_buyer_email: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('买家支付宝账号'),
          },
        ],
        currency_id: [
          { required: true, trigger: 'blur', message: this.__('货币编号') },
        ],
        currency_symbol_left: [
          { required: true, trigger: 'blur', message: this.__('左符号') },
        ],
        deposit_total_fee: [
          { required: true, trigger: 'blur', message: this.__('交易金额') },
        ],
        deposit_quantity: [
          { required: true, trigger: 'blur', message: this.__('购买数量') },
        ],
        deposit_price: [
          { required: true, trigger: 'blur', message: this.__('商品单价') },
        ],
        deposit_body: [
          { required: true, trigger: 'blur', message: this.__('商品描述') },
        ],
        deposit_gmt_create: [
          { required: true, trigger: 'blur', message: this.__('交易创建时间') },
        ],
        deposit_gmt_payment: [
          { required: true, trigger: 'blur', message: this.__('交易付款时间') },
        ],
        deposit_gmt_close: [
          { required: true, trigger: 'blur', message: this.__('') },
        ],
        deposit_is_total_fee_adjust: [
          { required: true, trigger: 'blur', message: this.__('是否调整总价') },
        ],
        deposit_use_coupon: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('是否使用红包买家'),
          },
        ],
        deposit_discount: [
          { required: true, trigger: 'blur', message: this.__('折扣') },
        ],
        deposit_notify_time: [
          { required: true, trigger: 'blur', message: this.__('通知时间') },
        ],
        deposit_notify_type: [
          { required: true, trigger: 'blur', message: this.__('通知类型') },
        ],
        deposit_notify_id: [
          { required: true, trigger: 'blur', message: this.__('通知校验编号') },
        ],
        deposit_sign_type: [
          { required: true, trigger: 'blur', message: this.__('签名方式') },
        ],
        deposit_sign: [
          { required: true, trigger: 'blur', message: this.__('签名') },
        ],
        deposit_extra_param: [
          { required: true, trigger: 'blur', message: this.__('额外参数') },
        ],
        deposit_service: [
          { required: true, trigger: 'blur', message: this.__('支付') },
        ],
        deposit_state: [
          { required: true, trigger: 'blur', message: this.__('支付状态') },
        ],
        deposit_async: [
          { required: true, trigger: 'blur', message: this.__('是否同步') },
        ],
        deposit_review: [
          { required: true, trigger: 'blur', message: this.__('收款确认') },
        ],
        deposit_enable: [
          { required: true, trigger: 'blur', message: this.__('是否作废') },
        ],
        store_id: [
          { required: true, trigger: 'blur', message: this.__('所属店铺') },
        ],
        user_id: [
          { required: true, trigger: 'blur', message: this.__('所属用户') },
        ],
        chain_id: [
          { required: true, trigger: 'blur', message: this.__('所属门店') },
        ],
        subsite_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>
