<template>
  <div class="app-container">
    <div class="box" v-loading="loading">
      <el-form :inline="true" ref="formRef" :model="form" :rules="rules" class="demo-form-inline">
        <h3>兑换豆配置</h3>
        <div class="item" style=" width: 1100px;">
          *赠送兑换豆比例
          <div>
            <el-form-item label="" prop="giftExchangeRatio">
              <!-- <el-input v-model="form.giftExchangeRatio" placeholder=""></el-input> -->
              <el-input-number v-model="form.giftExchangeRatio" controls-position="right" :min="0" :precision="2"></el-input-number>倍
            </el-form-item>
          </div>
          *按照景区订单实际支付金额
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          *新用户注册送兑换豆
          <div>
            <el-form-item label="" prop="newUserGivePoint">
              <el-input-number v-model="form.newUserGivePoint" controls-position="right" :min="0" :precision="0"></el-input-number>
            </el-form-item>
          </div>
        </div>
        <h3>积分商城订单流程配置</h3>
        <div class="item" style=" width: 1100px;">
          *自动收货天数
          <div>
            <el-form-item label="" prop="autoReceiptProcessDays">
              <el-input-number v-model="form.autoReceiptProcessDays" controls-position="right" :min="0" :precision="0"></el-input-number> 天
            </el-form-item>
          </div>
          *已发货订单 ，如果在期间未确认收货，系统自动完成收货，设置0天不自动收货
        </div>
        <h3>积分商城评论配置</h3>
        <div class="item" style=" width: 1100px;">
          *是否开启商品自动评论
          <div>
            <el-form-item label="" prop="commentOpen">
              <el-switch v-model="form.commentOpen"></el-switch>
            </el-form-item>
          </div>
        </div>
        <br>
        <div class="item" style="width: 1100px;">
          *自动评论天数
          <div>
            <el-form-item label="" :prop="form.commentOpen?'autoCommentProcessDays':''">
              <el-input-number v-model="form.autoCommentProcessDays" controls-position="right" :min="1" :precision="0"></el-input-number> 天
            </el-form-item>
          </div>
          *买家交易成功X天后买家未评论，系统将自动评论
        </div>
        <br>
        <div class="item" style=" width: 1100px;">
          *自动评论内容
          <div>
            <el-form-item label="" :prop="form.commentOpen?'defaultComment':''">
              <el-input v-model="form.defaultComment" placeholder="" maxlength="50"></el-input>
            </el-form-item>
          </div>
          *默认五星评价，评价内容根据配置显示
        </div>
        <el-divider></el-divider>
        <h3>核销商品分销配置</h3>
        <div class="item" style=" width: 1100px;">
          *是否开启分佣
          <div>
            <el-form-item label="" prop="openProfit">
              <el-switch v-model="form.openProfit"></el-switch>
            </el-form-item>
          </div>
          *开启后所有门票商品均可产生分佣
        </div>
        <br>
        <div class="item" style=" width: 1100px;">
          *分润比例
          <div>
            <el-form-item label="" prop="profitRatio">
              <el-input-number v-model="form.profitRatio" controls-position="right" :min="0" :precision="2"></el-input-number> %
            </el-form-item>
          </div>
          *按照订单实际付款金额进行分润
        </div>
        <h3>景区订单配置</h3>
        <div class="item" style=" width: 1100px;">
          *未支付订单取消时间
          <div>
            <el-form-item label="" prop="scenicOrderPayExpire">
              <el-input-number v-model="form.scenicOrderPayExpire" controls-position="right" :min="0" :precision="0"></el-input-number> 分钟
            </el-form-item>
          </div>
        </div>
        <br>
        <div class="item" style=" width: 1100px;">
          *订单结算利润百分比
          <div>
            <el-form-item label="" prop="settlementProfitRatio">
              <el-input-number v-model="form.settlementProfitRatio" controls-position="right" :min="0" :precision="4"></el-input-number> %
            </el-form-item>
          </div>
        </div>
        <h3>首页底部配置</h3>
        <div class="item" style=" width: 1100px;">
          文案一
          <div>
            <el-form-item label="" prop="homeFootFirst">
              <el-input style="width: 500px;" v-model="form.homeFootFirst" placeholder="" maxlength="50"></el-input>
            </el-form-item>
          </div>
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          文案二
          <div>
            <el-form-item label="" prop="homeFootSecond">
              <el-input style="width: 500px;" v-model="form.homeFootSecond" placeholder="" maxlength="50"></el-input>
            </el-form-item>
          </div>
        </div>
        <h3>页面分享配置（首页、个人中心、推荐商户）</h3>
        <div class="item" style=" width: 1100px;">
          分享标题：
          <div>
            <el-form-item label="" prop="shareTitle">
              <el-input style="width: 470px;" v-model="form.shareTitle" placeholder="" maxlength="50"></el-input>
            </el-form-item>
          </div>
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          分享图片：
          <div>
            <el-form-item label="" prop="shareImage">
              <imageUpload v-model="form.shareImage" :limit="1" unique="logo" />
            </el-form-item>
          </div>
        </div>
      </el-form>
      <div class="btnBox">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">保 存</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { shopSaleConfigSet, shopSaleConfigDefault } from '@/api/operating'
export default {
  data () {
    return {
      form: {
        giftExchangeRatio: undefined,
        autoReceiptProcessDays: undefined,
        autoCommentProcessDays: undefined,
        commentOpen: false,
        defaultComment: undefined,
        openProfit: false,
        profitRatio: undefined,
        scenicOrderPayExpire: undefined,
        settlementProfitRatio: undefined,
        shareTitle: undefined,
        shareImage: undefined
      },
      rules: {
        giftExchangeRatio: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        autoReceiptProcessDays: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        autoCommentProcessDays: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        defaultComment: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        profitRatio: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        scenicOrderPayExpire: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        settlementProfitRatio: [
          { required: true, message: '请输入', trigger: 'blur' }
        ]
      },
      buttonLoading: false,
      loading: false
    }
  },
  created () {
    this.getDetails()
  },
  methods: {
    getDetails () {
      this.loading = true
      shopSaleConfigDefault().then(res => {
        this.form = res.data
      }).finally(() => {
        this.loading = false
      })
    },
    submitForm () {
      this.$refs['formRef'].validate((valid) => {
        if (valid) {
          shopSaleConfigSet(this.form).then(res => {
            this.$message({
              message: '提交成功',
              type: 'success'
            })
          })
        }
      })
    }
  }
}
</script>

<style lang='scss' scoped>
h3 {
  font-weight: 700;
}
.item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  font-size: 14px;
  > div {
    margin: 0 10px;
  }
}
.hint {
  font-size: 12px;
  color: red;
}
.btnBox {
  margin: 20px 0 0 100px;
}
.el-form-item {
  margin-bottom: 0;
}
</style>