<template>

    <basic-container v-loading="loading">

      <el-card>
        <div slot="header" class="clearfix">
            <span style="font-weight: 800;">订单设置</span>
        </div>
        <el-form
          label-position="left"
          inline size="small"
          :rules="rules"
          :model="form"
          ref="normalForm"
          label-width="200px"
          class="layout_v">

          <div class="layout_h_v_c">
            <span>下单后超过</span>
            <el-form-item style="margin: 0;margin-left: 10px;margin-right: 10px;">
              <el-input v-model="form.cancelTime" :min="0" :max="99999" type="number" autocomplete="off"></el-input>
            </el-form-item>
            <span>分钟不支付订单，订单自动取消</span>
          </div>

          <div class="layout_h_v_c" style="margin-top: 16px;">
            <span>商家发货后 ，超过</span>
            <el-form-item style="margin: 0;margin-left: 10px;margin-right: 10px;">
              <el-input v-model="form.defaultReceiveDay" :min="0" :max="99999" type="number" autocomplete="off"></el-input>
            </el-form-item>
            <span>天默认用户已收货</span>
          </div>

        </el-form>
      </el-card>

      <el-card>
        <div slot="header" class="clearfix">
            <span style="font-weight: 800;">佣金/推广费</span>
        </div>
        <el-form
          label-position="left"
          inline size="small"
          :rules="rules"
          :model="form"
          ref="normalForm"
          label-width="200px"
          class="layout_v">

          <div class="layout_h_v_c">
            <span>推广员可获得商品售卖金额的</span>
            <el-form-item style="margin: 0;margin-left: 10px;margin-right: 10px;">
              <el-input v-model="form.promoteRewardRate" :min="0" :max="100" type="number" autocomplete="off"></el-input>
            </el-form-item>
            <span>%的佣金</span>
          </div>

          <div class="layout_h_v_c" style="margin-top: 16px;">
            <span>直接邀请者可获得商品售卖金额</span>
            <el-form-item style="margin: 0;margin-left: 10px;margin-right: 10px;">
              <el-input v-model="form.directRewardRate" :min="0" :max="100" type="number" autocomplete="off"></el-input>
            </el-form-item>
            <span>%的推广费</span>
          </div>

          <div class="layout_h_v_c" style="margin-top: 16px;">
            <span>间接邀请者可获得商品售卖金额</span>
            <el-form-item style="margin: 0;margin-left: 10px;margin-right: 10px;">
              <el-input v-model="form.indirectRewardRate" :min="0" :max="100" type="number" autocomplete="off"></el-input>
            </el-form-item>
            <span>%的推广费</span>
          </div>

        </el-form>
      </el-card>

      <el-card>
        <div slot="header" class="clearfix">
            <span style="font-weight: 800;">购买商品录制文字</span>
        </div>
        <el-form
          label-position="left"
          inline size="small"
          :rules="rules"
          :model="form"
          ref="normalForm"
          label-width="200px"
          class="layout_v">

          <div class="layout_h_v_c">
            <el-form-item style="margin: 0;margin-left: 10px;margin-right: 10px;">
              <el-input v-model="form.recordMarkPrefix" autocomplete="off"></el-input>
            </el-form-item>
            <span>+商品名称+</span>
            <el-form-item style="margin: 0;margin-left: 10px;margin-right: 10px;">
              <el-input v-model="form.recordMarkSuffix" autocomplete="off"></el-input>
            </el-form-item>
          </div>

        </el-form>
      </el-card>

      <div class="layout_v" style="width: 100%;">
        <el-button class="self_center" type="primary" :loading="saving" @click="submitForm">保存</el-button>
      </div>

    </basic-container>

</template>

<script>

  import { getSystemSet, configSystemSet } from '@/api/systemSet/systemSet.js'
  import { ZmMixin } from '@/mixins/ZmMixin.js'

  export default {
    mixins: [ZmMixin],
    data() {
      return {
        key: 'SYSTEM_SET_MALL_SET',
        loading: false,
        saving: false,
        rules: {

        },
        form: {
          cancelTime: '',
          defaultReceiveDay: '',
          promoteRewardRate: '',
          directRewardRate: '',
          indirectRewardRate: '',
          recordMarkPrefix: '',
          recordMarkSuffix: ''
        }
      }
    },
    created() {
      this.load()
    },
    methods: {
      load() {
        this.loading = true
        getSystemSet({key: this.key})
        .then(r => {
          this.loading = false
          let z = this.zmRes(r)
          if(z) {
            this.form.cancelTime = z.cancelTime
            this.form.defaultReceiveDay = z.defaultReceiveDay
            this.form.promoteRewardRate = z.promoteRewardRate * 100
            this.form.directRewardRate = z.directRewardRate * 100
            this.form.indirectRewardRate = z.indirectRewardRate * 100
            this.form.recordMarkPrefix = z.recordMarkPrefix
            this.form.recordMarkSuffix = z.recordMarkSuffix
          }
        })
        .catch(e => {
          this.loading = false
        })
      },
      submitForm() {
        if(!this.checkEmpty(this.form.cancelTime, "下单后超过分钟数")) {
          return
        }
        if(!this.checkEmpty(this.form.defaultReceiveDay, "商家发货后,超过天数")) {
          return
        }
        if(!this.checkEmpty(this.form.promoteRewardRate, "推广员可获得商品售卖金额百分比")) {
          return
        }
        if(!this.checkEmpty(this.form.directRewardRate, "直接邀请者可获得商品售卖金额百分比")) {
          return
        }
        if(!this.checkEmpty(this.form.indirectRewardRate, "间接邀请者可获得商品售卖金额百分比")) {
          return
        }
        if(!this.checkEmpty(this.form.recordMarkPrefix, "购买商品录制文字前缀")) {
          return
        }
        if(!this.checkEmpty(this.form.recordMarkSuffix, "购买商品录制文字后缀")) {
          return
        }
        this.saving = true
        configSystemSet({
          key: this.key,
          data: JSON.stringify({
            cancelTime: this.form.cancelTime,
            defaultReceiveDay: this.form.defaultReceiveDay,
            promoteRewardRate: this.form.promoteRewardRate / 100,
            directRewardRate: this.form.directRewardRate / 100,
            indirectRewardRate: this.form.indirectRewardRate / 100,
            recordMarkPrefix: this.form.recordMarkPrefix,
            recordMarkSuffix: this.form.recordMarkSuffix
          })
        })
        .then(r => {
          this.saving = false
          this.success("保存成功！")
        })
        .catch(e => {
          this.saving = false
        })
      }
    }
  }

</script>

<style scoped>


</style>
