<template>
  <div>
    <div class="title-box">小程序基础设置</div>
    <el-form ref="form" :model="form" :rules="rules" style="margin-top: 6px;" size="small" label-width="190px">
      <!-- <el-form-item label="服务老师注册口令" prop="sellerActivityCode">
        <el-input v-model="form.sellerActivityCode" style="width: 35%" />
      </el-form-item>
      <el-form-item label="文章全部解锁金额" prop="articlePrice">
        <el-input v-model="form.articlePrice" style="width: 35%" />
      </el-form-item>
      <el-form-item label="服务人员电话" prop="serviceStaffPhone">
        <el-input v-model="form.serviceStaffPhone" style="width: 35%" />
      </el-form-item> -->
      <el-form-item label="是否可以分享">
        <el-radio v-model="form.shareFlag" label="0">不可以</el-radio>
        <el-radio v-model="form.shareFlag" label="1">可以</el-radio>
      </el-form-item>
      <!-- <el-form-item label="能量大师的会员等级" prop="userHighestLevel">
        <el-input v-model="form.userHighestLevel" style="width: 35%" />
      </el-form-item> -->
      <!-- <div class="title-box">积分规则设置</div> -->
      <!-- <el-form-item :label="'积分签到'+item.day+'所得积分'" prop="userHighestLevel" v-for="(item,index) in form.signInfos" :key="index">
        <el-input v-model="item.signNum" style="width: 35%" />
      </el-form-item>
      <el-form-item label="完善个人信息所得积分" prop="completedNum">
        <el-input v-model="form.completedNum" style="width: 35%" />
      </el-form-item> -->
      <el-form-item>
        <el-button :loading="loading" size="medium" type="primary" @click="doSubmit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { setConfig, getConfigs } from '@/api/setConfig'
export default {
  data() {
    return {
      loading:false,
      form:{
        "signInfos": [],
        flag:0
      },
      rules: {
        sellerActivityCode: [
          { required: true, message: '服务老师注册口令不能为空', trigger: 'blur' }
        ],
        articlePrice: [
          { required: true, message: '文章全部解锁金额不能为空', trigger: 'blur' }
        ],
        serviceStaffPhone: [
          { required: true, message: '服务人员电话不能为空', trigger: 'blur' }
        ],
      },
      queryArr: [
        "share_flag",
      ]
    }
  },
  mounted(){
    this.getConfigs()
  },
  methods: {
    getConfigs(){
      getConfigs(this.queryArr).then((res)=>{
        this.form = res
      })
    },
    doSubmit() {
      this.loading = true;
      this.$refs['form'].validate((valid) => {
        if (valid) {
          setConfig(this.form).then(res => {
            console.log(res)
            this.$message({
              type:'success',
              message:'操作成功！'
            })
            this.getConfigs()
            this.loading = false;
          }).catch(err => {
            console.log(err.response.data.message)
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped>
.title-box{
  font-size: 24px;
  padding: 20px;
}
</style>
