<template>
  <div>
    <div class="form-wrap"  style="margin-bottom:180px;">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="90px" class="demo-ruleForm">
      <dm-sub-title type="fill" text="积分获取策略" style="margin-bottom: 20px;margin-top:10px;"/>
      <el-form-item label="获取规则:" prop="integralGetStatus">
        <div>
          <el-radio v-model="ruleForm.integralGetStatus" label="0" @change="radioEvent">不获取积分</el-radio>
        </div>
        <div class="margin-20 integralGet">
          <el-radio v-model="ruleForm.integralGetStatus" label="1">每消费</el-radio>
          <!-- <el-input v-model="ruleForm.integralGet.fee"  @blur="formatInputFee($event)"></el-input> -->
          <el-input-number v-model="ruleForm.integralGet.fee" placeholder="请输入" :precision="1" :controls="false" :max="10000.0" :min="0.1"></el-input-number>
          <label>元，获取 </label>
          <el-input-number v-model="ruleForm.integralGet.integral" placeholder="请输入" step-strictly :controls="false"></el-input-number>
          <!-- <el-input v-model="ruleForm.integralGet.integral"  @keyup.native="formatInput($event)"></el-input> --><label>积分。取整策略为</label>
          <el-select v-model="ruleForm.integralGetStrategy" placeholder="请选择" style="width:115px;margin-left:5px;">
            <el-option v-for="item in cateOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select><br/>
          <span style="color: #909399;font-size:12px; padding-left:22px;"> 例：根据消费金额计算出积分为4.3，选择「四舍五入」和「抹零」时为4积分，选择「进位制」则为5积分</span>
        </div>
        <div class="form-child margin-20" v-if="ruleForm.integralGetStatus == 1">
          <el-form-item label="折扣控制:" prop="" label-width="100px">
            <div class="radio-cell">
              <el-radio class="integralGetDiscountControlLower1" v-model="ruleForm.integralGetDiscountControl" label="1" @change="radioEvent3">所有折扣商品都适用</el-radio>
            </div>
            <div class="radio-cell margin-20">
              <el-radio v-model="ruleForm.integralGetDiscountControl" label="2">折扣</el-radio>
              <!-- <el-input v-model="ruleForm.integralGetDiscountControlLower" @change="formatInputChange($event)"></el-input> -->
              <el-input-number  placeholder="请输入" v-model="ruleForm.integralGetDiscountControlLower" :precision="2" :controls="false" :max="10.0" :min="1"></el-input-number>
              <label>至</label>
              <!-- <el-input v-model="ruleForm.integralGetDiscountControlUpper" @change="formatInputChange($event)"></el-input> -->
              <el-input-number  placeholder="请输入" v-model="ruleForm.integralGetDiscountControlUpper" :precision="2" :controls="false" :max="10.0" :min="1"></el-input-number>
              <label>折商品都适用</label>
               <span style="font-size: 12px;color: #828282;line-height: 1;padding-left: 10px;">折扣范围1-10，填写8.8，则表示“打8.8折”，也即商品原价*8.8/10=商品折后价</span>
            </div>
          </el-form-item>
          <el-form-item label="积分冻结期:" prop="integralGetFreezeDays" label-width="100px" class="padding-bottom-20 margin-20 integralGetFreezeDays">
            <label>自获取之日起</label>
            <el-input v-model="ruleForm.integralGetFreezeDays" placeholder="请输入" @keyup.native="formatInput($event)"></el-input>
            <label>天</label>
            <span style="font-size: 12px;color: #828282;padding-left: 10px;">仅对通过订单获取的积分生效，活动类获取的积分没有冻结期</span></el-form-item>
        </div>
      </el-form-item>
      <dm-sub-title type="fill" text="积分抵现策略" style="margin-bottom: 20px;margin-top:30px; "/>
      <el-form-item label="抵现规则:" prop="integralUseStatus" class="margin-20">
        <div>
          <el-radio v-model="ruleForm.integralUseStatus" label="0" @change="radioEvent1">不支持抵现</el-radio>
        </div>
        <div class="margin-20">
          <el-radio class="integralUse" v-model="ruleForm.integralUseStatus" label="1">每使用</el-radio>
          <!-- <el-input v-model="ruleForm.integralUse.integral"  @keyup.native="formatInput($event)"></el-input> -->
          <el-input-number v-model="ruleForm.integralUse.integral" placeholder="请输入" step-strictly :controls="false"></el-input-number>
          <label>积分，抵 </label>
          <el-input-number v-model="ruleForm.integralUse.fee" placeholder="请输入" :precision="1" :controls="false" :max="10000.0" :min="0.1"></el-input-number>
          <!-- <el-input v-model="ruleForm.integralUse.fee"  @blur="formatInputFee($event)"></el-input> -->
          <label>元</label>
        </div>
      <div class="form-child margin-20" v-if="ruleForm.integralUseStatus == 1">
        <el-form-item label="折扣控制:" prop="region">
          <div class="radio-cell">
            <el-radio v-model="ruleForm.integralUseDiscountControl" label="1" @change="radioEvent4">所有折扣商品都适用</el-radio>
          </div>
          <div class="radio-cell margin-20">
            <el-radio class="integralUseDiscountControlLower1" v-model="ruleForm.integralUseDiscountControl" label="2">折扣</el-radio>
            <!-- <el-input v-model="ruleForm.integralUseDiscountControlLower" @change="formatInputChange($event)"></el-input> -->
            <el-input-number v-model="ruleForm.integralUseDiscountControlLower" placeholder="请输入" :precision="2" :controls="false" :max="10.0" ></el-input-number>
            <label>至</label>
            <!-- <el-input v-model="ruleForm.integralUseDiscountControlUpper" @change="formatInputChange($event)"></el-input> -->
            <el-input-number v-model="ruleForm.integralUseDiscountControlUpper" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1"></el-input-number>
            <label>折商品都适用</label>
            <span style="font-size: 12px;color: #828282;line-height: 1;padding-left: 10px;">折扣范围1-10，填写8.8，则表示“打8.8折”，也即商品原价*8.8/10=商品折后价</span>
          </div>
        </el-form-item>
        <el-form-item label="比例限制:" prop="name" class="padding-bottom-20 margin-20 useProportionalRestriction">
          <label>最多可抵用商品金额的 </label>
          <el-input placeholder="请输入" v-model="ruleForm.useProportionalRestriction" @keyup.native="formatInput($event)"></el-input>%
        </el-form-item>
      </div>
      </el-form-item>
      <el-form-item label="积分成本:" required class="integralCost">
        <label>每使用</label>
        <el-input-number v-model="ruleForm.integralCost.integral" placeholder="请输入" step-strictly :controls="false"></el-input-number>
        <!-- <el-input v-model="ruleForm.integralCost.integral"  @keyup.native="formatInput($event)"></el-input> -->
        <label>积分，承担 </label>
        <!-- <el-input v-model="ruleForm.integralCost.fee"  @blur="formatInputFee($event)"></el-input> -->
        <el-input-number v-model="ruleForm.integralCost.fee" placeholder="请输入" :precision="1" :controls="false" :max="10000.0" :min="0.1"></el-input-number>
        <label>元</label>
      </el-form-item>
      <dm-sub-title type="fill" text="积分有效期" style="margin-bottom: 20px; margin-top:40px;"/>
       <el-form-item label="有效期:" prop="integralExpireType" class="padding-0 yearY" >
        <el-tooltip placement="right" effect="light">
            <div slot="content" style="line-height:20px">
              <p style="color:#595959 font-size:14px;font-weight:600">规则说明：</p>
              <p style="color:#e6a23c">
                仅GIC计算积分时，配置的积分有效期才会生效，<br/>
                ERP计算积分时，此配置项不生效；
              </p>
              <ul>
                <li>1、永久有效：客户获取的积分永久有效，系统不会清零；</li>
                <li>2、按年失效：在第X年的X月X日失效：例：设置第二年的12月1日失效，则2021年获取的所有积分在2022年12月1日失效；</li>
                <li>3、按月失效：在第X个月的X日失效：例：设置第二月的1日失效，则3月获取的所有积分在4月1日失效；</li>
                <li>4、按天失效：每天获取的所有积分在获取之日起365天后失效：例：设置365天，则2022年12月1号获取的积分在2023年12月1号失效；</li>
                <li>5、修改积分有效期后，已经获取的积分有效期不变，后续获取的积分按照修改后的积分有效期生效；</li>
              </ul>
            </div>
            <i class="iconfont icon-QuestionCircleOutlined" style="font-size:12px;color:#606266;"></i>
           </el-tooltip>
           <span style="font-size: 12px;color: #909399;line-height: 1;padding-left: 5px;">适用于所有方式获取的积分</span>
            <div class="radio-cell mb20">
              <el-radio  v-model="ruleForm.integralExpireType" label="1" @change="radioExpireType1">永久有效</el-radio>
            </div>
           <div class="radio-cell mb20">
            <el-radio  v-model="ruleForm.integralExpireType" label="2" @change="radioExpireType1"><label>按年失效：</label></el-radio>
            <label>每年获取的所有积分，在</label>
            <el-select v-model="yearY" placeholder="请选择" style="width:120px;margin:0 10px;">
              <el-option v-for="n in yearList" :key="n.key" :label="n.value" :value="n.key"></el-option>
            </el-select>
            <label>的</label>
            <el-select v-model="yearM" placeholder="请选择" style="width:120px;margin:0 10px;">
              <el-option v-for="n in 12" :key="n" :label="n" :value="n"></el-option>
            </el-select>
            <label>月</label>
            <el-select v-model="yearD" placeholder="请选择" style="width:120px;margin:0 10px;">
              <el-option v-for="n in dayList" :key="n.key" :label="n.value" :value="n.key"></el-option>
            </el-select>
            <label>日失效</label>
          </div>
          <div class="radio-cell mb20">
            <el-radio  v-model="ruleForm.integralExpireType" label="3" @change="radioExpireType1"><label>按月失效：</label></el-radio>
            <label>每月获取的所有积分，在</label>
            <el-select v-model="mouthM" placeholder="请选择" style="width:120px;margin:0 10px;">
              <el-option  v-for="n in mouthList" :key="n.key" :label="n.value" :value="n.key"></el-option>
            </el-select>
            <label>的</label>
            <el-select v-model="mouthD" placeholder="请选择" style="width:120px;margin:0 10px;">
              <el-option v-for="n in dayList" :key="n.key" :label="n.value" :value="n.key"></el-option>
            </el-select>
            <label>日失效</label>
          </div>
          <div class="radio-cell">
            <el-radio  v-model="ruleForm.integralExpireType" label="0" @change="radioExpireType1"><label>按天失效：</label></el-radio>
            <label>每天获取的所有积分，在获取之日起</label>
            <el-input placeholder="请输入" v-model="ruleForm.effectiveTime" @keyup.native="formatInput($event)"></el-input>
            <label>天后失效</label>
            <span style="font-size: 12px;color: #909399;line-height: 1;padding-left: 10px;">建议不超过3年(1095天)</span>
          </div>
        </el-form-item>
        <dm-sub-title type="fill" text="积分说明" style="margin-bottom: 20px; margin-top:40px;"/>
        <p style="font-size:12px; color:#606266">积分说明展示在会员小程序-积分商城-积分明细页</p>
        <el-form-item label="" label-width="0" prop="desc" class="margin-20">
          <div class="tinymce-wrap">
            <editor id="tinymce" v-model="ruleForm.integralScript" :init="init"></editor>
          </div>
          <!-- <div v-html='tinymceHtml'></div> -->
        </el-form-item>
    </el-form>
  </div>
   <div class="bottom">
        <el-button :disabled="contactBool" type="primary" @click="submitForm('ruleForm')" style="margin:13px 0 0 -220px;">保存</el-button>
      </div>
  </div>
</template>
<script type="text/javascript">
import { postRequest, postForm } from '@/api/api';
import { log } from '@/utils/index.js';
import errMsg from '@/common/js/error';
import strLength from '@/common/js/strlen';
import tinymce from 'tinymce/tinymce';
import 'tinymce/themes/modern/theme';
import Editor from '@tinymce/tinymce-vue';
import 'tinymce/plugins/image';
import 'tinymce/plugins/link';
import 'tinymce/plugins/code';
import 'tinymce/plugins/table';
import 'tinymce/plugins/lists';
import 'tinymce/plugins/contextmenu';
import 'tinymce/plugins/wordcount';
import 'tinymce/plugins/colorpicker';
import 'tinymce/plugins/textcolor';
import { scrollToError } from '@/utils/validate';
export default {
  name: 'pointSystem',
  props: {
    pointInfo: Object,
    projectName: String,
    contactBool: Boolean
  },
  data() {
    // 天数
    const dayList = ()=> {
      let arr = []
      for(let i = 1; i < 28; i++){
        arr.push({key: i,value: i})
      }
      arr.push({key: 0, value: '月末'})
      return arr;
    }
    // 月数
    const mouthList = ()=> {
      let arr = []
      for(let i = 2; i < 37; i++){
        arr.push({key: i,value: `第${i}个月`})
      }
      return arr;
    }
    // 年数
    const yearList = ()=> {
      let arr = []
      for(let i = 2; i < 5; i++){
        arr.push({key: i,value: `第${i}年`})
      }
      return arr;
    }
    return {
      scrollToError,
      dayList: dayList(),
      mouthList: mouthList(),
      mouthM: '', //按月失效 月
      mouthD: '', //按月失效 月
      yearList: yearList(),
      yearY: '', //按年失效 年
      yearM: '', //按年失效 月
      yearD: '', //按年失效 日
      repProjectName: 'gic-clique',

      // form
      cateOptions: [
        {
          value: '1',
          label: '四舍五入'
        },
        {
          value: '2',
          label: '抹零'
        },
        {
          value: '3',
          label: '进位制'
        }
      ],
      ruleForm: {
        // 积分获取规则
        memberIntegralId: '', // id
        enterpriseId: '', //企业id
        integralGet: { fee: undefined, integral: undefined }, //  积分获取
        integralUse: { fee: undefined, integral: undefined }, //积分使用
        integralGetStrategy: '1',
        integralScript: '', //说明
        integralGetStatus: '0', //积分获得开启（0：否，1：是）
        integralUseStatus: '0', //积分使用开启（0：否，1：是）
        effectiveTime: '0', //积分有效期
        integralGetDiscountControl: '2',
        integralGetDiscountControlUpper: undefined, // 折扣控制 折扣范围 下限
        integralGetDiscountControlLower: undefined, // 折扣控制 折扣范围 上限
        integralGetFreezeDays: '', // 获取积分冻结天数
        integralUseDiscountControl: '1', // 折扣控制 1所有折扣商品适用 2折扣范围
        integralUseDiscountControlUpper: undefined,
        integralUseDiscountControlLower: undefined,
        useProportionalRestriction: '90', //抵现比例限制
        integralCost: { fee: undefined, integral: undefined }, //积分成本
        integralExpireType: '0', //积分有效期类型 0 未默认滚动到期 1永久 2 按年失效 3按月失效
        integralExpireRule: '', //积分有效期规则 年 x(年),x(月),x(日，为0标识月末)  月,x(月),x(日，为0标识月末)
      },
      rules: {
        integralGetStatus: [
          { required: true, message: '请选择积分获取规则', trigger: 'blur' },
        ],
        integralUseStatus: [
          { required: true, message: '请选择抵现规则', trigger: 'blur' },
        ],
        integralExpireType: [
          { required: true, message: '请选择积分有效期', trigger: 'blur' },
        ],
        // strategyName: [
        //   { required: true, message: '请填写策略名称', trigger: 'blur' },
        // ],strategyName: [
        //   { required: true, message: '请填写策略名称', trigger: 'blur' },
        // ]
      },

      // tinymce
      tinymceHtml: '请输入内容',
      init: {
        language_url: 'static/tinymce/zh_CN.js',
        language: 'zh_CN',
        skin_url: 'static/tinymce/skins/lightgray',
        height: 300,
        // 图片上传
        // without images_upload_url set, Upload tab won't show up
        // images_upload_url: '',
        // images_upload_base_path: '/some/basepath',
        images_upload_credentials: true, //是否应传递cookie等跨域的凭据
        // images_upload_handler提供三个参数：blobInfo, success, failure
        images_upload_handler: (blobInfo, success, failure) => {
          // log(blobInfo)
          this.handleImgUpload(blobInfo, success, failure);
        },
        // 添加插件
        plugins: 'link lists image code table colorpicker textcolor wordcount contextmenu',
        toolbar: 'bold italic underline strikethrough | fontsizeselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent blockquote | undo redo | link unlink image code | removeformat',
        branding: false,
        setup: function(editor) {
          // 点击编辑框回调
          editor.on('click', function(e) {
            log('Editor was clicked');
          });
        }
      }
    };
  },
  created() {
    // this.selectReplayStyle()
    this.getPointInfos();
  },
  methods: {
    radioEvent() {
      this.ruleForm.integralGet.integral = undefined;
      this.ruleForm.integralGet.fee =undefined;
    },
    radioEvent1() {
      this.ruleForm.integralUse.integral = undefined;
      this.ruleForm.integralUse.fee =undefined;
    },
    radioEvent3() {
      this.ruleForm.integralGetDiscountControlLower = undefined;
      this.ruleForm.integralGetDiscountControlUpper =undefined;
    },
    radioEvent4() {
      this.ruleForm.integralUseDiscountControlLower = undefined;
      this.ruleForm.integralUseDiscountControlUpper =undefined;
    },
    radioExpireType1(e) {
      if(e==0){
        this.yearY='';
        this.yearM='';
        this.yearD='';
        this.mouthM='';
        this.mouthD='';
      }else if(e==1) {
        this.yearY='';
        this.yearM='';
        this.yearD='';
        this.mouthM='';
        this.mouthD='';
        this.ruleForm.effectiveTime = undefined;
      }else if (e==2) {
        this.mouthM='';
        this.mouthD='';
        this.ruleForm.effectiveTime = undefined;
      } else if (e == 3) {
        this.yearY='';
        this.yearM='';
        this.yearD='';
        this.ruleForm.effectiveTime = undefined;
      }
    },
    // 保存
    submitForm(formName) {
      let that = this;
      this.$refs[formName].validate(valid => {
        if (valid) {
          // log(that.pointInfo);
          // log(that.ruleForm);
          let data = JSON.parse(JSON.stringify(that.ruleForm));

          // 非空验证
          let flag = !data.integralGet.fee || !data.integralGet.integral;
          if (data.integralGetStatus == 1 && flag) {
            this.scrollToError(this, 'integralGet');
            that.$message.error('请填写积分获取规则');
            return;
          }

          if (data.integralGetStatus == 1) {
            if (!Number(data.integralGet.fee)) {
              this.scrollToError(this, 'integralGet');
              that.$message.error('积分获取规则中的消费金额不能为0');
              return;
            }
            if (!Number(data.integralGet.integral)) {
              this.scrollToError(this, 'integralGet');
              that.$message.error('积分获取规则中的获取积分不能为0');
              return;
            }
          }
          // log(String(data.integralGetFreezeDays));

          if (data.integralGetStatus == 1 && String(data.integralGetFreezeDays) == '') {
            this.scrollToError(this, 'integralGetFreezeDays');
            // 积分冻结期
            that.$message.error({
              duration: 1000,
              message: '请填写积分冻结期'
            });
            return;
          }

          if(data.integralExpireType == ''){ // 积分有效期类型
            this.scrollToError(this, 'yearY');
            that.$message.error({
              duration: 1000,
              message: "请设置积分有效期"
            })
            return;
          }

          if(data.integralExpireType ==3 && (this.mouthM == '' || this.mouthD == -1)) {
            this.scrollToError(this, 'yearY');
            that.$message.error({
              duration: 1000,
              message: "请完善积分有效期信息"
            })
            return;
          }else if(data.integralExpireType ==2 && (this.yearY == '' || this.yearM == '' || this.yearD == -1 )) {
            this.scrollToError(this, 'yearY');
            that.$message.error({
              duration: 1000,
              message: "请完善积分有效期信息"
            })
            return;
          } else if (data.integralExpireType ==0  && data.effectiveTime=='') {
            this.scrollToError(this, 'yearY');
            that.$message.error({
              duration: 1000,
              message: "请完善积分有效期信息"
            })
            return;
          }else if ( String(data.integralExpireType)== 0 && data.effectiveTime=='' && parseInt(data.effectiveTime) < 1) {
            this.scrollToError(this, 'yearY');
            that.$message.error({
              duration: 1000,
              message: '积分有效期不能低于最低限制'
            });
            return;
          }


          let tag = !data.integralUse.fee || !data.integralUse.integral || !data.integralCost.integral || !data.integralCost.fee || !parseInt(data.useProportionalRestriction);
          if (data.integralUseStatus == 1 && tag) {
            this.scrollToError(this, 'integralUse');
            that.$message.error({
              duration: 1000,
              message: '请填写积分抵现规则'
            });
            return;
          }
          if (data.integralUseStatus == 1) {
            if (!Number(data.integralUse.fee)) {
              this.scrollToError(this, 'integralUse');
              that.$message.error('积分抵现规则中的抵现金额不能为0');
              return;
            }
            if (!Number(data.integralUse.integral)) {
              this.scrollToError(this, 'integralUse');
              that.$message.error('积分抵现规则中的使用积分不能为0');
              return;
            }
          }
          // 积分成本
          if (!Number(data.integralCost.fee)) {
            this.scrollToError(this, 'integralCost');
            that.$message.error('积分成本中的承担金额不能为0');
            return;
          }
          if (!Number(data.integralCost.integral)) {
            this.scrollToError(this, 'integralCost');
            that.$message.error('积分成本中的使用积分不能为0');
            return;
          }

          // 折扣率判断
          if (data.integralGetStatus == 1 && data.integralGetDiscountControl == 2) {
            let flagA = Number(data.integralGetDiscountControlUpper) <= Number(data.integralGetDiscountControlLower);
            if (!data.integralGetDiscountControlLower || !data.integralGetDiscountControlUpper) {
              this.scrollToError(this, 'integralGetDiscountControlLower1');
              that.$message.error('请输入商品折扣值');
              return;
            }
            if (flagA) {
              this.scrollToError(this, 'integralGetDiscountControlLower1');
              that.$message.error('积分获取规则中的折扣格式有误');
              return;
            }
          }
          if (data.integralUseStatus == 1 && data.integralUseDiscountControl == 2) {
            let flagB = Number(data.integralUseDiscountControlUpper) <= Number(data.integralUseDiscountControlLower);
            if (!data.integralUseDiscountControlLower || !data.integralUseDiscountControlUpper) {
              this.scrollToError(this, 'integralUseDiscountControlLower1');
              that.$message.error('请输入商品折扣值');
              return;
            }
            if (flagB) {
              this.scrollToError(this, 'integralUseDiscountControlLower1');
              that.$message.error('积分抵现规则中的折扣格式有误');
              return;
            }
          }

          if (data.useProportionalRestriction > 100) {
            this.scrollToError(this, 'useProportionalRestriction');
            that.$message.error('比例限制文本格式有误');
            return;
          }

          // 获取规则需要乘以10
          if (!data.integralGetStrategy || data.integralGetStrategy == 0) {
            data.integralGetStrategy = '1';
          }
          data.integralGet.fee = parseInt(data.integralGet.fee * 10);
          data.integralGet.integral = parseInt(data.integralGet.integral * 10);
          data.integralGet = JSON.stringify(data.integralGet)?JSON.stringify(data.integralGet):that.ruleForm.integralGet;
          data.integralUse = JSON.stringify(data.integralUse)?JSON.stringify(data.integralUse):that.ruleForm.integralUse;
          data.integralCost = JSON.stringify(data.integralCost)?JSON.stringify(data.integralCost):that.ruleForm.integralCost;

          if( data.integralExpireType == 0){
            data.integralExpireRule = ''
          }else if(data.integralExpireType == 1) {
            data.integralExpireRule = ''
            delete data.effectiveTime
          } else if(data.integralExpireType == 2) {
            data.integralExpireRule = `${this.yearY},${this.yearM},${this.yearD}`
            delete data.effectiveTime
          }else if(data.integralExpireType == 3) {
            data.integralExpireRule = `${this.mouthM},${this.mouthD}`
            delete data.effectiveTime
          }
          that.saveInfo(data);
        } else {
          // log('error submit!!');
          setTimeout(() => {
            var isError = document.getElementsByClassName("is-error");
            if (isError[0].querySelector('input')) {
              isError[0].querySelector('input').focus();
            } else if (isError[0].querySelector('textarea')) {
              isError[0].querySelector('textarea').focus();
            }
          }, 1)
          return false;
        }
      });
    },

    saveInfo(data) {
      let that = this;
      let param = data;
      param.requestProject = that.repProjectName;
      log(param, 9090)
      postRequest('/api-admin/save-member-integral-setting', param)
        .then(res => {
          // log(res,res.data,res.data.errorCode)
          let resData = res.data;
          if (resData.errorCode == 0) {
            that.$message({
              message: '保存成功',
              type: 'success'
            });
            // 更新原数据
            // that.updateData();
            return;
          }
          // that.userFormVisible = false;
          that.$message.error({
            duration: 1000,
            message: resData.message
          });
        })
        .catch(function(error) {
          // log(error);
          // that.toLogin()
          // that.userFormVisible = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    // 上传图片
    handleImgUpload(blobInfo, success, failure) {
      let that = this;
      let formdata = new FormData();
      formdata.set('upload_file', blobInfo.blob());
      formdata.set('requestProject', that.repProjectName);
      //log(formdata)
      postForm('/api-plug/upload-img', formdata)
        .then(res => {
          success(res.data.result[0].qcloudImageUrl);
        })
        .catch(res => {
          //log(res)
          failure('error');
        });
    },

    // 输入框输入校验数字
    formatInput(e) {
      let that = this;
      that.ruleForm.integralUse.fee = strLength.getCharVal(String(that.ruleForm.integralUse.fee).replace(/[^\d]/g,''),6) || undefined
      that.ruleForm.integralUse.integral = strLength.getCharVal(String(that.ruleForm.integralUse.integral).replace(/[^\d]/g,''),8) || undefined

      that.ruleForm.integralCost.fee = strLength.getCharVal(String(that.ruleForm.integralCost.fee).replace(/[^\d]/g,''),6) || undefined
      that.ruleForm.integralCost.integral = strLength.getCharVal(String(that.ruleForm.integralCost.integral).replace(/[^\d]/g,''),8) || undefined
      that.ruleForm.integralGetFreezeDays = strLength.getCharVal(String(that.ruleForm.integralGetFreezeDays).replace(/[^\d]/g, ''), 4);
      that.ruleForm.effectiveTime = strLength.getCharVal(String(that.ruleForm.effectiveTime).replace(/[^\d]/g, ''), 4);

      that.ruleForm.useProportionalRestriction = strLength.getCharVal(String(that.ruleForm.useProportionalRestriction).replace(/[^\d]/g, ''), 3) || '0';
      if (parseInt(that.ruleForm.useProportionalRestriction) > 100) {
        that.ruleForm.useProportionalRestriction = 100;
      }

      that.$forceUpdate();
    },
    // 通用积分
    getPointInfos() {
      var that = this
      var param = {
        requestProject: that.projectName
      }

      postRequest('/api-admin/get-member-integral-setting',param)
        .then((res) => {
          var resData = res.data
          // console.log(resData, 'ppp');
          if (resData.errorCode == 0) {
            // that.pointInfo = that.handleData(resData.result.memberIntegral)
            that.ruleForm = that.handleData(resData.result.memberIntegral);
            that.ruleForm.integralExpireRule = that.ruleForm.integralExpireRule ? that.ruleForm.integralExpireRule.split(',') : '';
            if(this.ruleForm.integralGetStatus == 0) {
              this.ruleForm.integralGet.fee = undefined;
              this.ruleForm.integralGet.integral = undefined;
            }
            if(this.ruleForm.integralUseStatus == 0) {
              this.ruleForm.integralUse.fee = undefined;
              this.ruleForm.integralUse.integral = undefined;
            }
            // 给定一个默认值
            if (that.ruleForm.integralGetDiscountControl == 0) {
              this.ruleForm.integralGetDiscountControl = '1';
            }
            if (that.ruleForm.integralUseDiscountControl == 0) {
              this.ruleForm.integralUseDiscountControl = '1';
            }
            if(this.ruleForm.integralGetDiscountControl == 1) {
              this.ruleForm.integralGetDiscountControlLower = undefined;
              this.ruleForm.integralGetDiscountControlUpper = undefined
            }
            if(this.ruleForm.integralUseDiscountControl == 1) {
              this.ruleForm.integralUseDiscountControlLower = undefined;
              this.ruleForm.integralUseDiscountControlUpper = undefined
            }
            if(this.ruleForm.integralExpireType == 'null'){
              this.ruleForm.integralExpireType = '0';
            }else if(that.ruleForm.integralExpireType == 2) {
              this.yearY = Number(this.ruleForm.integralExpireRule[0]);
              this.yearM = Number(this.ruleForm.integralExpireRule[1]);
              this.yearD = Number(this.ruleForm.integralExpireRule[2]);
              this.ruleForm.effectiveTime = ''
              console.log(that.yearY, that.yearM, that.yearD);
            }else if(this.ruleForm.integralExpireType == 3) {
              this.mouthM = Number(this.ruleForm.integralExpireRule[0]);
              this.mouthD = Number(this.ruleForm.integralExpireRule[1]);
              this.ruleForm.effectiveTime = ''
            }else if(that.ruleForm.integralExpireType == 1) {
              that.ruleForm.effectiveTime = ''
            }

            return;
          }
          errMsg.errorMsg(resData)
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    // 处理表单中数据
    handleData(item) {
      item.integralGetStatus = String(item.integralGetStatus);
      item.integralUseStatus = String(item.integralUseStatus);
      item.integralGetStrategy = String(item.integralGetStrategy);
      item.integralGetDiscountControl = String(item.integralGetDiscountControl);
      item.integralUseDiscountControl = String(item.integralUseDiscountControl);
      item.integralGetDiscountControlUpper = String(item.integralGetDiscountControlUpper);
      item.integralGetDiscountControlLower = String(item.integralGetDiscountControlLower);
      item.integralUseDiscountControlUpper = String(item.integralUseDiscountControlUpper);
      item.integralUseDiscountControlLower = String(item.integralUseDiscountControlLower);
      item.integralExpireType = String(item.integralExpireType);
      item.integralExpireRule = String(item.integralExpireRule);

      // item.integralGet = JSON.parse(item.integralGet);
      // item.integralUse = JSON.parse(item.integralUse);
      // item.integralCost = JSON.parse(item.integralCost);
      let isJSONBool1 = this.isJSON(item.integralGet);
      let isJSONBool2 = this.isJSON(item.integralUse);
      let isJSONBool3 = this.isJSON(item.integralCost);
      if(isJSONBool1){
        item.integralGet = JSON.parse(item.integralGet);
      }else{  // 不是json  先转成对象再转成json
        item.integralGet = JSON.parse(JSON.stringify(eval('('+ item.integralGet +')')))
      }
      if(isJSONBool2){
        item.integralUse = JSON.parse(item.integralUse);
      }else{
        item.integralUse = JSON.parse(JSON.stringify(eval('('+ item.integralUse +')')))
      }
      if(isJSONBool3){
        item.integralCost = JSON.parse(item.integralCost);
      }else{
        item.integralCost = JSON.parse(JSON.stringify(eval('('+ item.integralCost +')')))
      }
      item.integralGet.fee = Number(item.integralGet.fee / 10).toFixed(1);
      item.integralGet.integral = Number(item.integralGet.integral / 10);
      return item;
    },
    isJSON(str) {
      if (typeof str == 'string') {
        try {
          // var obj=JSON.parse(str);
          // console.log('转换成功：'+obj);
          return true;
        } catch(e) {
          // console.log('error：'+str+'!!!'+e);
          return false;
        }
      }
    },
  },
  watch: {
    projectName: function(newData, oldData) {
      let that = this;
      // log("新数据:",newData,oldData)
      that.repProjectName = newData || 'gic-web';
    },
    // pointInfo: {
    //   handle: function(newData, oldData) {
    //     console.log(newData, oldData, 'newData, oldData');
    //     let that = this;
    //     if (newData) {
    //       that.ruleForm = newData;
    //       that.ruleForm.integralExpireRule = that.ruleForm.integralExpireRule.split(',')
    //       if(this.ruleForm.integralGetStatus == 0) {
    //         this.ruleForm.integralGet.fee = undefined;
    //         this.ruleForm.integralGet.integral = undefined;
    //       }
    //       if(this.ruleForm.integralUseStatus == 0) {
    //         this.ruleForm.integralUse.fee = undefined;
    //         this.ruleForm.integralUse.integral = undefined;
    //       }
    //       // 给定一个默认值
    //       if (newData.integralGetDiscountControl == 0) {
    //         this.ruleForm.integralGetDiscountControl = '1';
    //       }
    //       if (newData.integralUseDiscountControl == 0) {
    //         this.ruleForm.integralUseDiscountControl = '1';
    //       }
    //       if(this.ruleForm.integralGetDiscountControl == 1) {
    //         this.ruleForm.integralGetDiscountControlLower = undefined;
    //         this.ruleForm.integralGetDiscountControlUpper = undefined
    //       }
    //       if(this.ruleForm.integralUseDiscountControl == 1) {
    //         this.ruleForm.integralUseDiscountControlLower = undefined;
    //         this.ruleForm.integralUseDiscountControlUpper = undefined
    //       }
    //       if(this.ruleForm.integralExpireType == null){
    //         this.ruleForm.integralExpireType = 1;
    //       }else if(that.ruleForm.integralExpireType == 2) {
    //         this.yearY = Number(this.ruleForm.integralExpireRule[0]);
    //         this.yearM = Number(this.ruleForm.integralExpireRule[1]);
    //         this.yearD = Number(this.ruleForm.integralExpireRule[2]);
    //         this.ruleForm.effectiveTime = ''
    //         console.log(that.yearY, that.yearM, that.yearD);
    //       }else if(this.ruleForm.integralExpireType == 3) {
    //         this.mouthM = Number(this.ruleForm.integralExpireRule[0]);
    //         this.mouthD = Number(this.ruleForm.integralExpireRule[1]);
    //         this.ruleForm.effectiveTime = ''
    //       }else if(that.ruleForm.integralExpireType == 1) {
    //         that.ruleForm.effectiveTime = ''
    //       }
    //     }
    //   },
    //   immediate: true
    // }
  },
  components: {
    Editor
  },
  mounted() {
    let that = this;
    tinymce.init({});
    // 传递的数据非空赋值
    console.log(Object.keys(that.pointInfo), 'Object.keys(that.pointInfo)');
    if (that.pointInfo) {
      if (Object.keys(that.pointInfo).length) {
        that.ruleForm = that.pointInfo;
      }
    }
  }
};
</script>
<style lang="less" scoped>
.mb20 {
  margin-bottom: 20px;
}
.bottom{
  position: fixed;
  bottom: 0px;
  left: 200px;
  width: 100%;
  height: 55px;
  // margin: 25px;
  text-align: center;
  background: #FFFFFF;
  box-shadow: 1px -2px 8px 0px rgba(220, 223, 230, 0.6);
}
.form-wrap {
  .el-radio {
    margin-right: 0;
  }
  .el-input,
  /deep/ .el-input-number {
    width: 115px;
    padding: 0 5px;
    .el-input__inner {
      text-align: left;
    }
  }

  /deep/ .el-form {
    .el-form-item:last-child {
      margin-bottom: 0;
    }
  }

  .padding-0 {
    padding: 0;
  }
  .padding-bottom-20 {
    padding-bottom: 20px;
  }

  .form-child {
    width: 100%;
    padding: 15px 20px 1px 0px;
    background: #f5f6f9;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
  }

  .margin-20 {
    margin-top: 20px;
  }

  .tinymce-wrap {
    width: 1000px;
    height: 254px;

    /deep/ .mce-tinymce {
      -webkit-box-shadow: none;
      -moz-box-shadow: none;
      box-shadow: none;
      border: 1px solid #dcdfe6;
    }

    /deep/ .mce-panel {
      border: 0px solid #dcdfe6;
    }
  }
}
</style>
