<template>
  <div class="app-container">
    <!-- <el-row> -->
    <!-- <el-col :span="6"> -->
    <div class="box">
      <el-form ref="form" :model="form" :rules="dataRule" class="demo-ruleForm" label-width="auto">
        <!-- <h3>积分配置</h3>
        <el-form-item label="赠送积分比例" prop="giftExchangeRatio">
          <el-input-number v-model="form.giftExchangeRatio" controls-position="right" :min="0" :precision="2"></el-input-number>倍,*按照订单实际支付金额
        </el-form-item> -->
        <!-- <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> -->
        <h3>评论设置</h3>
        <el-form-item label="是否开启默认评论">
          <el-switch v-model="form.commentOpen" />
        </el-form-item>
        <div v-if="form.commentOpen">
          <!-- <el-form-item label="买家交易成功" prop="autoCommentProcessDays">
            <el-input-number :precision="0" v-model="form.autoCommentProcessDays" :min="7" :max="30"></el-input-number> 天后买家未评价，系统默认评价（最小7天，最大30天）
          </el-form-item> -->
          <el-form-item label="默认评价内容" prop="defaultComment">
            <el-input v-model="form.defaultComment" style="width: 500px;" placeholder=""></el-input>
          </el-form-item>
        </div>
        <h3>订单流程设置</h3>
        <!-- <el-row :gutter="20"> -->
        <!-- <el-col :span="6">
            <el-form-item label="未支付订单"  prop="delayDays">
              <el-input-number :precision="0" v-model="form.delayDays" :min="0" :max="89" size="large"></el-input-number>天(0-7)
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label=""  prop="delayHours">
              <el-input-number :precision="0" v-model="form.delayHours" :min="0" :max="23" size="large"></el-input-number>小时(0-23)
            </el-form-item>
          </el-col> -->
        <!-- <el-col :span="6"> -->
        <!-- <el-form-item label="未支付订单" prop="delayMinutes">
          <el-input-number :precision="0" s v-model="form.delayMinutes" :min="10" :max="59" size="large"></el-input-number> 分钟(10-59)
        </el-form-item> -->
        <!-- </el-col> -->
        <!-- </el-row> -->

        <el-form-item label="已发货订单" prop="autoReceiptProcessDays">
          <el-input-number :precision="0" v-model="form.autoReceiptProcessDays" :min="3"
            :max="30"></el-input-number>天后自动确认收货(3-30天)
        </el-form-item>
        <el-form-item label="已收货订单" prop="autoCloseRightsProcessDays">
          <el-input-number :precision="0" v-model="form.autoCloseRightsProcessDays" :min="3"
            :max="30"></el-input-number>天后关闭退款、退货功能(3-30天)
        </el-form-item>
        <div>
          <h3>售后流程设置</h3>
          <el-form-item label="买家发起退款申请" prop="applyRefundAutoProcessDays">
            <el-input-number :precision="0" v-model="form.applyRefundAutoProcessDays" :min="3"
              :max="30"></el-input-number> 天后商家未处理，系统自动同意退款(3-30天)
          </el-form-item>
          <el-form-item label="买家发起退货退款申请" prop="applyReturnAutoProcessDays">
            <el-input-number :precision="0" v-model="form.applyReturnAutoProcessDays" :min="3"
              :max="30"></el-input-number> 天后商家未处理，系统自动同意退款(3-30天)
          </el-form-item>
          <el-form-item label="卖家同意退货后" prop="agreeReturnAutoProcessDays">
            <el-input-number :precision="0" v-model="form.agreeReturnAutoProcessDays" :min="3"
              :max="30"></el-input-number> 天后买家未处理，系统自动拒绝售后（3-30天）
          </el-form-item>
          <el-form-item label="买家已退货后" prop="returnedAutoProcessDays">
            <el-input-number :precision="0" v-model="form.returnedAutoProcessDays" :min="3" :max="30"></el-input-number>
            天后商家未处理，系统自动确认收货(3-30天)
          </el-form-item>
        </div>
        <!-- <h3>核销商品分销配置</h3>
        <el-form-item label="是否开启分佣" prop="openProfit">
          <el-switch v-model="form.openProfit"></el-switch>*开启后所有门票商品均可产生分佣
        </el-form-item>
        <br>
        <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>
        <br>
        <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> -->
        <!-- <h3>页面分享配置</h3>
        <el-form-item label="分享标题" prop="shareTitle">
          <el-input style="width: 470px;" v-model="form.shareTitle" placeholder="" maxlength="50"></el-input>
        </el-form-item>
        <el-form-item label="分享图片" prop="shareImage">
          <imageUpload v-model="form.shareImage" :limit="1" unique="logo" />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" :loading="btnLoading" @click="onSubmit('form')">提 交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { shopSaleConfigSet, shopSaleConfigDefault } from '@/api/operating'
export default {
  data() {
    return {
      form: {
        commentOpen: false, // 是否开启商品自动评论
        // open_payment: false, // 是否开启小程序支付
        // autoCommentProcessDays: 7, // 买家交易成功多少天后买家未评论，系统将自动评论默认7天(7-30天)
        defaultComment: '默认好评', // 系统评论内容为  用户超时未评，系统自动好评
        // delayDays: 0, // 支付延时配置
        // delayHours: 0, // 支付延时配置（小时数，最大23小时）
        delayMinutes: 10, // 付延时配置（分钟数，最小10分，最大59分钟），
        autoReceiptProcessDays: null, // 已发货订单,多少天后自动确认收货（最小10天，最大30天）
        autoCloseRightsProcessDays: null, // 维权最后天数最小是15天，维权最后天数最大是30天
        applyReturnAutoProcessDays: null, // 买家发起退货退款申请多少天后商家未处理，系统将自动同意维权，默认3天(3-30天) 
        applyRefundAutoProcessDays: null, // 买家发起退款申请多少天后商家未处理，系统将自动同意，默认3天(3-30天)
        agreeReturnAutoProcessDays: null, // 商家同意退货多少天后买家未处理，系统将自动拒绝维权，默认3天(3-30天)
        returnedAutoProcessDays: null, // 买家已退货(退货填单)多少天后商家未处理，系统将自动收货。默认3天(3-30天)

        giftExchangeRatio: null,
        // newUserGivePoint: null,
        // openProfit: null,
        // profitRatio: null,
        // settlementProfitRatio: null
      },
      dataRule: {
        giftExchangeRatio: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        delayMinutes: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        newUserGivePoint: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        commentOpen: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        defaultComment: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        delayDays: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        autoReceiptProcessDays: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        autoCloseRightsProcessDays: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        applyRefundAutoProcessDays: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        applyReturnAutoProcessDays: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        agreeReturnAutoProcessDays: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        returnedAutoProcessDays: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        openProfit: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        profitRatio: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        settlementProfitRatio: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
      },
      btnLoading: false
    }
  },
  mounted() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      shopSaleConfigDefault().then((res) => {
        this.form = res.data
      })
    },
    // 提交
    onSubmit(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          shopSaleConfigSet(this.form).then((res) => {
            this.$message({
              message: '提交成功',
              type: 'success'
            })
            this.getInfo()
          }).finally(() => {
            this.btnLoading = false
          })
        } else {
          console.log('error submit!!')
          this.$message.error('请完成必填输入！')
          return false
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
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;
// }
// .mb10 {
//   margin-bottom: 10px;
// }</style>
