<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="order_id">
        <el-input v-model="form.order_id" :placeholder="__('订单编号')" />
      </el-form-item>
      <el-form-item :label="__('订单标题')" prop="order_title">
        <el-input v-model="form.order_title" :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="subsite_id">
        <el-input v-model="form.subsite_id" :placeholder="__('所属分站')" />
      </el-form-item>
      <el-form-item :label="__('买家编号')" prop="buyer_user_id">
        <el-input v-model="form.buyer_user_id" :placeholder="__('买家编号')" />
      </el-form-item>
      <el-form-item :label="__('订单种类')" prop="kind_id">
        <el-input v-model="form.kind_id" :placeholder="__('订单种类')" />
      </el-form-item>
      <el-form-item :label="__('锁定状态')" prop="order_lock_status">
        <el-input
          v-model="form.order_lock_status"
          :placeholder="__('锁定状态')"
        />
      </el-form-item>
      <el-form-item :label="__('订单是否结算')" prop="order_is_settlemented">
        <el-input
          v-model="form.order_is_settlemented"
          :placeholder="__('订单是否结算')"
        />
      </el-form-item>
      <el-form-item :label="__('订单结算时间')" prop="order_settlement_time">
        <el-input
          v-model="form.order_settlement_time"
          :placeholder="__('订单结算时间')"
        />
      </el-form-item>
      <el-form-item
        :label="__('买家针对订单对店铺评价')"
        prop="order_buyer_evaluation_status"
      >
        <el-input
          v-model="form.order_buyer_evaluation_status"
          :placeholder="__('买家针对订单对店铺评价')"
        />
      </el-form-item>
      <el-form-item
        :label="__('卖家评价状态')"
        prop="order_seller_evaluation_status"
      >
        <el-input
          v-model="form.order_seller_evaluation_status"
          :placeholder="__('卖家评价状态')"
        />
      </el-form-item>
      <el-form-item :label="__('订单年份-索引查询')" prop="order_year">
        <el-input
          v-model="form.order_year"
          :placeholder="__('订单年份-索引查询')"
        />
      </el-form-item>
      <el-form-item :label="__('订单月份-索引查询')" prop="order_month">
        <el-input
          v-model="form.order_month"
          :placeholder="__('订单月份-索引查询')"
        />
      </el-form-item>
      <el-form-item :label="__('订单日-索引查询')" prop="order_day">
        <el-input
          v-model="form.order_day"
          :placeholder="__('订单日-索引查询')"
        />
      </el-form-item>
      <el-form-item :label="__('下单时间')" prop="order_time">
        <el-input v-model="form.order_time" :placeholder="__('下单时间')" />
      </el-form-item>
      <el-form-item :label="__('当前状态的处理时间')" prop="order_deal_time">
        <el-input
          v-model="form.order_deal_time"
          :placeholder="__('当前状态的处理时间')"
        />
      </el-form-item>
      <el-form-item :label="__('买家删除')" prop="order_buyer_hidden">
        <el-input
          v-model="form.order_buyer_hidden"
          :placeholder="__('买家删除')"
        />
      </el-form-item>
      <el-form-item :label="__('店铺删除')" prop="order_shop_hidden">
        <el-input
          v-model="form.order_shop_hidden"
          :placeholder="__('店铺删除')"
        />
      </el-form-item>
      <el-form-item :label="__('支付方式')" prop="payment_type_id">
        <el-input
          v-model="form.payment_type_id"
          :placeholder="__('支付方式')"
        />
      </el-form-item>
      <el-form-item :label="__('付款时间')" prop="payment_time">
        <el-input v-model="form.payment_time" :placeholder="__('付款时间')" />
      </el-form-item>
      <el-form-item :label="__('订单状态')" prop="order_state_id">
        <el-input v-model="form.order_state_id" :placeholder="__('订单状态')" />
      </el-form-item>
      <el-form-item :label="__('订单审核')" prop="order_is_review">
        <el-input
          v-model="form.order_is_review"
          :placeholder="__('订单审核')"
        />
      </el-form-item>
      <el-form-item :label="__('财务状态')" prop="order_finance_review">
        <el-input
          v-model="form.order_finance_review"
          :placeholder="__('财务状态')"
        />
      </el-form-item>
      <el-form-item :label="__('付款状态')" prop="order_is_paid">
        <el-input v-model="form.order_is_paid" :placeholder="__('付款状态')" />
      </el-form-item>
      <el-form-item :label="__('出库状态')" prop="order_is_out">
        <el-input v-model="form.order_is_out" :placeholder="__('出库状态')" />
      </el-form-item>
      <el-form-item :label="__('发货状态')" prop="order_is_shipped">
        <el-input
          v-model="form.order_is_shipped"
          :placeholder="__('发货状态')"
        />
      </el-form-item>
      <el-form-item :label="__('收货状态')" prop="order_is_received">
        <el-input
          v-model="form.order_is_received"
          :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="delivery_type_id">
        <el-input
          v-model="form.delivery_type_id"
          :placeholder="__('配送方式')"
        />
      </el-form-item>
      <el-form-item :label="__('线下订单')" prop="order_is_offline">
        <el-input
          v-model="form.order_is_offline"
          :placeholder="__('线下订单')"
        />
      </el-form-item>
      <el-form-item :label="__('购买类型')" prop="cart_type_id">
        <el-input v-model="form.cart_type_id" :placeholder="__('购买类型')" />
      </el-form-item>
      <el-form-item :label="__('是否打印')" prop="order_express_print">
        <el-input
          v-model="form.order_express_print"
          :placeholder="__('是否打印')"
        />
      </el-form-item>
      <el-form-item :label="__('活动编号')" prop="activity_id">
        <el-input v-model="form.activity_id" :placeholder="__('活动编号')" />
      </el-form-item>
      <el-form-item :label="__('活动类型')" prop="activity_type_id">
        <el-input
          v-model="form.activity_type_id"
          :placeholder="__('活动类型')"
        />
      </el-form-item>
      <el-form-item :label="__('销售员编号')" prop="salesperson_id">
        <el-input
          v-model="form.salesperson_id"
          :placeholder="__('销售员编号')"
        />
      </el-form-item>
      <el-form-item :label="__('是否ERP同步')" prop="order_is_sync">
        <el-input
          v-model="form.order_is_sync"
          :placeholder="__('是否ERP同步')"
        />
      </el-form-item>
      <el-form-item :label="__('是否自营')" prop="store_is_selfsupport">
        <el-input
          v-model="form.store_is_selfsupport"
          :placeholder="__('是否自营')"
        />
      </el-form-item>
      <el-form-item :label="__('店铺类型')" prop="store_type">
        <el-input v-model="form.store_type" :placeholder="__('店铺类型')" />
      </el-form-item>
      <el-form-item :label="__('ERP订单编号')" prop="order_erp_id">
        <el-input
          v-model="form.order_erp_id"
          :placeholder="__('ERP订单编号')"
        />
      </el-form-item>
      <el-form-item :label="__('分销商编号')" prop="distributor_user_id">
        <el-input
          v-model="form.distributor_user_id"
          :placeholder="__('分销商编号')"
        />
      </el-form-item>
      <el-form-item :label="__('跨境订单')" prop="order_is_cb">
        <el-input v-model="form.order_is_cb" :placeholder="__('跨境订单')" />
      </el-form-item>
      <el-form-item :label="__('是否报关')" prop="order_is_cb_sync">
        <el-input
          v-model="form.order_is_cb_sync"
          :placeholder="__('是否报关')"
        />
      </el-form-item>
      <el-form-item :label="__('来源订单')" prop="src_order_id">
        <el-input v-model="form.src_order_id" :placeholder="__('来源订单')" />
      </el-form-item>
      <el-form-item :label="__('是否代发')" prop="order_is_transfer">
        <el-input
          v-model="form.order_is_transfer"
          :placeholder="__('是否代发')"
        />
      </el-form-item>
      <el-form-item :label="__('转单执行结果')" prop="order_is_transfer_note">
        <el-input
          v-model="form.order_is_transfer_note"
          :placeholder="__('转单执行结果')"
        />
      </el-form-item>
      <el-form-item :label="__('佣金是否发放')" prop="order_fx_is_settlemented">
        <el-input
          v-model="form.order_fx_is_settlemented"
          :placeholder="__('佣金是否发放')"
        />
      </el-form-item>
      <el-form-item :label="__('佣金结算时间')" prop="order_fx_settlement_time">
        <el-input
          v-model="form.order_fx_settlement_time"
          :placeholder="__('佣金结算时间')"
        />
      </el-form-item>
      <el-form-item :label="__('订单类型')" prop="order_type">
        <el-input v-model="form.order_type" :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/order/info'

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

      this.rules = {
        order_id: [
          { required: true, trigger: 'blur', message: this.__('订单编号') },
        ],
        order_title: [
          { required: true, trigger: 'blur', message: this.__('订单标题') },
        ],
        store_id: [
          { required: true, trigger: 'blur', message: this.__('卖家店铺编号') },
        ],
        subsite_id: [
          { required: true, trigger: 'blur', message: this.__('所属分站') },
        ],
        buyer_user_id: [
          { required: true, trigger: 'blur', message: this.__('买家编号') },
        ],
        kind_id: [
          { required: true, trigger: 'blur', message: this.__('订单种类') },
        ],
        order_lock_status: [
          { required: true, trigger: 'blur', message: this.__('锁定状态') },
        ],
        order_is_settlemented: [
          { required: true, trigger: 'blur', message: this.__('订单是否结算') },
        ],
        order_settlement_time: [
          { required: true, trigger: 'blur', message: this.__('订单结算时间') },
        ],
        order_buyer_evaluation_status: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('买家针对订单对店铺评价'),
          },
        ],
        order_seller_evaluation_status: [
          { required: true, trigger: 'blur', message: this.__('卖家评价状态') },
        ],
        order_year: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('订单年份-索引查询'),
          },
        ],
        order_month: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('订单月份-索引查询'),
          },
        ],
        order_day: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('订单日-索引查询'),
          },
        ],
        order_time: [
          { required: true, trigger: 'blur', message: this.__('下单时间') },
        ],
        order_deal_time: [
          {
            required: true,
            trigger: 'blur',
            message: this.__('当前状态的处理时间'),
          },
        ],
        order_buyer_hidden: [
          { required: true, trigger: 'blur', message: this.__('买家删除') },
        ],
        order_shop_hidden: [
          { required: true, trigger: 'blur', message: this.__('店铺删除') },
        ],
        payment_type_id: [
          { required: true, trigger: 'blur', message: this.__('支付方式') },
        ],
        payment_time: [
          { required: true, trigger: 'blur', message: this.__('付款时间') },
        ],
        order_state_id: [
          { required: true, trigger: 'blur', message: this.__('订单状态') },
        ],
        order_is_review: [
          { required: true, trigger: 'blur', message: this.__('订单审核') },
        ],
        order_finance_review: [
          { required: true, trigger: 'blur', message: this.__('财务状态') },
        ],
        order_is_paid: [
          { required: true, trigger: 'blur', message: this.__('付款状态') },
        ],
        order_is_out: [
          { required: true, trigger: 'blur', message: this.__('出库状态') },
        ],
        order_is_shipped: [
          { required: true, trigger: 'blur', message: this.__('发货状态') },
        ],
        order_is_received: [
          { required: true, trigger: 'blur', message: this.__('收货状态') },
        ],
        chain_id: [
          { required: true, trigger: 'blur', message: this.__('门店编号') },
        ],
        delivery_type_id: [
          { required: true, trigger: 'blur', message: this.__('配送方式') },
        ],
        order_is_offline: [
          { required: true, trigger: 'blur', message: this.__('线下订单') },
        ],
        cart_type_id: [
          { required: true, trigger: 'blur', message: this.__('购买类型') },
        ],
        order_express_print: [
          { required: true, trigger: 'blur', message: this.__('是否打印') },
        ],
        activity_id: [
          { required: true, trigger: 'blur', message: this.__('活动编号') },
        ],
        activity_type_id: [
          { required: true, trigger: 'blur', message: this.__('活动类型') },
        ],
        salesperson_id: [
          { required: true, trigger: 'blur', message: this.__('销售员编号') },
        ],
        order_is_sync: [
          { required: true, trigger: 'blur', message: this.__('是否ERP同步') },
        ],
        store_is_selfsupport: [
          { required: true, trigger: 'blur', message: this.__('是否自营') },
        ],
        store_type: [
          { required: true, trigger: 'blur', message: this.__('店铺类型') },
        ],
        order_erp_id: [
          { required: true, trigger: 'blur', message: this.__('ERP订单编号') },
        ],
        distributor_user_id: [
          { required: true, trigger: 'blur', message: this.__('分销商编号') },
        ],
        order_is_cb: [
          { required: true, trigger: 'blur', message: this.__('跨境订单') },
        ],
        order_is_cb_sync: [
          { required: true, trigger: 'blur', message: this.__('是否报关') },
        ],
        src_order_id: [
          { required: true, trigger: 'blur', message: this.__('来源订单') },
        ],
        order_is_transfer: [
          { required: true, trigger: 'blur', message: this.__('是否代发') },
        ],
        order_is_transfer_note: [
          { required: true, trigger: 'blur', message: this.__('转单执行结果') },
        ],
        order_fx_is_settlemented: [
          { required: true, trigger: 'blur', message: this.__('佣金是否发放') },
        ],
        order_fx_settlement_time: [
          { required: true, trigger: 'blur', message: this.__('佣金结算时间') },
        ],
        order_type: [
          { 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>
