<template>
  <div class="right-wrap">
    <topNavNew :navpath="navpath"></topNavNew>
    <div class="right-content">
      <div class="right-box">
        <div class="attention-wrap">
          <div class="form-wrap">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
              <dm-sub-title text="基本信息" type="fill" style="margin-bottom: 20px"></dm-sub-title>
              <el-form-item label="策略名称：" prop="strategyName">
                <el-input v-model="ruleForm.strategyName" class="w-340" placeholder="请输入策略名称" @keyup.native="value => toInput(value)"> </el-input>
                <label class="input-label">{{ cateNameLength }}/20</label>
              </el-form-item>
              <dm-sub-title text="渠道配置" type="fill" style="margin: 40px 0 20px 0"></dm-sub-title>
              <template v-for="(item, index) in ruleForm.channelList">
                <!-- 线下渠道 -->
                <template v-if="item.channelType == 3">
                  <el-form-item label="线下渠道：" prop="" :key="index">
                    <el-switch v-model="item.openStatus"> </el-switch>
                    <span class="setting-tips">客户在线下门店产生的订单</span>
                  <div class="form-child" v-if="item.openStatus" :key="index">
                    <el-form-item label="消费门店：" prop="region" label-width="85px" style="margin-bottom: 20px">
                      <dm-store-selector :isClique="true" :scenesVal="scencs" :options="options" :isAdd="isAdd" :uuid.sync="uuid" ref="storeGroup"></dm-store-selector>
                    </el-form-item>
                    <el-form-item label="适用商品：" prop="name" class="padding-0" label-width="85px" style="margin-bottom: 20px">
                      <el-select v-model="item.channelRelationProType" placeholder="请选择" @change="changeGood($event)">
                        <el-option v-for="item in applyGoods" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                      <!-- 二级 -->
                      <span class="span-txt" ref="treeinput" v-if="item.channelRelationProType == 2" @click="toggle('brand')">已选择 {{ item.strategyGoodsRelationIdArr ? item.strategyGoodsRelationIdArr.length : 0 }} 个品牌 </span>
                      <span class="span-txt" ref="treeinput" v-if="item.channelRelationProType == 3" @click="toggle('brand')">已选择 {{ item.strategyGoodsRelationIdArr ? item.strategyGoodsRelationIdArr.length : 0 }} 个品类 </span>
                      <treeselect v-if="item.channelRelationProType == 2 || item.channelRelationProType == 3" placeholder="" noOptionsText="暂无数据" noResultsText="无数据" :multiple="true" :always-open="goodsOpen" :options="goodsTreeOptions" :value-consists-of="valueConsistsOf" v-model="item.strategyGoodsRelationIdArr" />
                      <el-button v-if="item.channelRelationProType == 4" @click="showGoodsDialog">已选0件商品</el-button>
                    </el-form-item>
                    <el-form-item label="折扣控制：" prop="region" label-width="85px">
                      <div class="radio-cell">
                        <el-radio v-model="item.integralUseDiscountControl" label="1" @change="radioEventN(0)">所有折扣商品都适用</el-radio>
                      </div>
                      <div class="radio-cell margin-20">
                        <el-radio v-model="item.integralUseDiscountControl" label="2">折扣</el-radio>
                        <el-input-number v-model="item.integralUseDiscountControlLower" :precision="2" :controls="false" :max="10.0" :min="1" :step="0.01" placeholder="请输入" style="width: 115px"></el-input-number>
                        <label>至</label>
                        <el-input-number v-model="item.integralUseDiscountControlUpper" :precision="2" :controls="false" :max="10.0" :min="1" placeholder="请输入" style="width: 115px"></el-input-number>
                        <label>折商品都适用</label>
                        <span class="setting-tips">折扣范围1-10，填写8.8，则表示“打8.8折”，也即商品原价*8.8/10=商品折后价</span>
                      </div>
                    </el-form-item>
                  </div>
                  </el-form-item>
                </template>

                <template v-if="item.channelType == 1">
                  <!-- 达摩微商城 -->
                  <el-form-item label="达摩微商城：" prop="" :key="index">
                    <el-switch v-model="item.openStatus"> </el-switch>
                    <span class="setting-tips">客户在达摩微商城产生的订单</span>
                  <div class="form-child margin-20" v-if="item.openStatus == true" :key="index">
                    <el-form-item label="选择商户：" label-width="85px" style="margin-bottom: 20px">
                      <el-select size="small" v-model="item.enterpriseRelationIdArr" placeholder="请选择" multiple>
                        <el-option v-for="(item, ind) in mechantOption" :key="ind" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="适用商品：" class="padding-0" label-width="85px" style="margin-bottom: 20px">
                      <el-select v-model="item.channelRelationProType" placeholder="请选择" @change="changeGood($event)">
                        <el-option v-for="item in applyGoods" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                      <!-- 二级 -->
                      <span class="span-txt" ref="treeinput" v-if="item.channelRelationProType == 2" @click="toggle('wx')">已选择 {{ item.goodsRelationIdArr ? item.goodsRelationIdArr.length : 0 }} 个品牌 </span>
                      <span class="span-txt" ref="treeinput" v-if="item.channelRelationProType == 3" @click="toggle('wx')">已选择 {{ item.goodsRelationIdArr ? item.goodsRelationIdArr.length : 0 }} 个品类 </span>
                      <treeselect v-if="item.channelRelationProType == 2 || item.channelRelationProType == 3" placeholder="" noOptionsText="暂无数据" noResultsText="无数据" :multiple="true" :always-open="wxOpen" :options="goodsTreeOptions" :value-consists-of="valueConsistsOf" v-model="item.goodsRelationIdArr" @select="selectWx($event, index, item)" />
                      <!--model=item.strategyGoodsRelationIdArr和上一个相同会有问题 -->
                      <el-button v-if="item.channelRelationProType == 4" @click="showGoodsDialog">已选0件商品</el-button>
                    </el-form-item>
                    <el-form-item label="折扣控制：" prop="region" label-width="85px" style="margin-bottom: 20px">
                      <div class="radio-cell">
                        <el-radio v-model="item.integralUseDiscountControl" label="1" @change="radioEventN(1)">所有折扣商品都适用</el-radio>
                      </div>
                      <div class="radio-cell margin-20">
                        <el-radio v-model="item.integralUseDiscountControl" label="2">折扣</el-radio>
                        <el-input-number v-model="item.integralUseDiscountControlLower" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>至</label>
                        <el-input-number v-model="item.integralUseDiscountControlUpper" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>折商品都适用</label>
                        <span class="setting-tips">折扣范围1-10，填写8.8，则表示“打8.8折”，也即商品原价*8.8/10=商品折后价</span>
                      </div>
                    </el-form-item>
                  </div>
                  </el-form-item>
                </template>
                <!-- 微盟渠道-->
                <template v-if="item.channelType == 9">
                  <el-form-item label="微盟渠道：" prop="" :key="index">
                    <el-switch v-model="item.openStatus"> </el-switch>
                    <span class="setting-tips">客户在微盟微商城产生的订单</span>
                  <div class="form-child margin-20" v-if="item.openStatus == true" :key="index">
                    <el-form-item label="选择商户：" label-width="85px" style="margin-bottom: 20px">
                      <el-select size="small" v-model="item.enterpriseRelationIdArr" placeholder="请选择" multiple @change="onStoreChange(item)">
                        <el-option v-for="(item, ind) in mechantOption" :key="ind" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item v-if="Array.isArray(item.enterpriseRelationIdArr) && item.enterpriseRelationIdArr.length > 0" label="消费门店：" label-width="85px" style="margin-bottom: 20px">
                      <el-select v-model="storeValue" v-if="!isJinHua">
                        <el-option label="所有门店" value=""></el-option>
                      </el-select>
                      <vue-gic-store-new v-else :scenesVal="scencs" :options="options" :isAdd="isAdd" :uuid.sync="wmuuid" ref="wmstoreGroup"></vue-gic-store-new>
                    </el-form-item>
                    <el-form-item v-if="Array.isArray(item.enterpriseRelationIdArr) && item.enterpriseRelationIdArr.length > 0" label="适用商品：" class="padding-0" label-width="85px" style="margin-bottom: 20px">
                      <el-select v-model="item.channelRelationProType" placeholder="请选择">
                        <el-option v-for="item in wMGoodOption" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="折扣控制：" prop="region" class="input-margin-b" label-width="85px">
                      <div class="radio-cell">
                        <el-radio v-model="item.integralUseDiscountControl" label="1" @change="radioEventN(2)">所有折扣商品都适用</el-radio>
                      </div>
                      <div class="radio-cell margin-20">
                        <el-radio v-model="item.integralUseDiscountControl" label="2">折扣</el-radio>
                        <el-input-number v-model="item.integralUseDiscountControlLower" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>至</label>
                        <el-input-number v-model="item.integralUseDiscountControlUpper" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>折商品都适用</label>
                        <span class="setting-tips">折扣范围1-10，填写8.8，则表示“打8.8折”，也即商品原价*8.8/10=商品折后价</span>
                      </div>
                    </el-form-item>
                  </div>
                  </el-form-item>
                </template>
                <!-- 天猫 -->
                <template v-if="item.channelType == 8">
                  <el-form-item label="天猫渠道：" prop="" :key="index">
                    <el-switch v-model="item.openStatus"> </el-switch>
                    <span class="setting-tips">客户在天猫店铺产生的订单</span>
                  <div class="form-child margin-20" v-if="item.openStatus == true" :key="index">
                    <el-form-item label="选择商户：" label-width="85px" style="margin-bottom: 20px">
                      <el-select size="small" v-model="item.enterpriseRelationIdArr" placeholder="请选择" multiple>
                        <el-option v-for="(item, ind) in mechantOption" :key="ind" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="折扣控制：" prop="region" label-width="85px" style="margin-bottom: 20px">
                      <div class="radio-cell">
                        <el-radio v-model="item.integralUseDiscountControl" label="1" @change="radioEventN(3)">所有折扣商品都适用</el-radio>
                      </div>
                      <div class="radio-cell margin-20">
                        <el-radio v-model="item.integralUseDiscountControl" label="2">折扣</el-radio>
                        <el-input-number v-model="item.integralUseDiscountControlLower" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>至</label>
                        <el-input-number v-model="item.integralUseDiscountControlUpper" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>折商品都适用</label>
                        <span class="setting-tips">折扣范围1-10，填写8.8，则表示“打8.8折”，也即商品原价*8.8/10=商品折后价</span>
                      </div>
                    </el-form-item>
                  </div>
                  </el-form-item>
                </template>
                <!-- 抖音 11 -->
                <template v-if="item.channelType == 11">
                  <el-form-item label="抖音渠道：" prop="" :key="index">
                    <el-switch v-model="item.openStatus"> </el-switch>
                    <span class="setting-tips">客户在抖音店铺产生的订单</span>
                  <div class="form-child margin-20" v-if="item.openStatus == true" :key="index">
                    <el-form-item label="选择商户：" label-width="85px" style="margin-bottom: 20px">
                      <el-select size="small" v-model="item.enterpriseRelationIdArr" placeholder="请选择" multiple>
                        <el-option v-for="(item, ind) in mechantOption" :key="ind" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="折扣控制：" prop="region" label-width="85px" style="margin-bottom: 20px">
                      <div class="radio-cell">
                        <el-radio v-model="item.integralUseDiscountControl" label="1" @change="radioEventN(4)">所有折扣商品都适用</el-radio>
                      </div>
                      <div class="radio-cell margin-20">
                        <el-radio v-model="item.integralUseDiscountControl" label="2">折扣</el-radio>
                        <el-input-number v-model="item.integralUseDiscountControlLower"  placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>至</label>
                        <el-input-number v-model="item.integralUseDiscountControlUpper" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>折商品都适用</label>
                        <span class="setting-tips">折扣范围1-10，填写8.8，则表示“打8.8折”，也即商品原价*8.8/10=商品折后价</span>
                      </div>
                    </el-form-item>
                  </div>
                  </el-form-item>
                </template>
                <!-- 其他 10 -->
                <template v-if="item.channelType == 10">
                  <el-form-item label="其他渠道：" prop="" :key="index">
                    <el-switch v-model="item.openStatus"> </el-switch>
                    <span class="setting-tips">客户在其它渠道产生的订单</span>
                  <div class="form-child margin-20" v-if="item.openStatus == true" :key="index">
                    <el-form-item label="选择商户：" label-width="85px" style="margin-bottom: 20px">
                      <el-select size="small" v-model="item.enterpriseRelationIdArr" placeholder="请选择" multiple>
                        <el-option v-for="(item, ind) in mechantOption" :key="ind" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="折扣控制：" prop="region" label-width="85px" style="margin-bottom: 20px">
                      <div class="radio-cell">
                        <el-radio v-model="item.integralUseDiscountControl" label="1" @change="radioEventN(5)">所有折扣商品都适用</el-radio>
                      </div>
                      <div class="radio-cell margin-20">
                        <el-radio v-model="item.integralUseDiscountControl" label="2">折扣</el-radio>
                        <el-input-number v-model="item.integralUseDiscountControlLower" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>至</label>
                        <el-input-number v-model="item.integralUseDiscountControlUpper" placeholder="请输入" :precision="2" :controls="false" :max="10.0" :min="1" style="width: 115px"></el-input-number>
                        <label>折商品都适用</label>
                        <span class="setting-tips">折扣范围1-10，填写8.8，则表示“打8.8折”，也即商品原价*8.8/10=商品折后价</span>
                      </div>
                    </el-form-item>
                  </div>
                  </el-form-item>
                </template>
              </template>

              <dm-sub-title text="规则配置" type="fill" style="margin: 40px 0 20px"></dm-sub-title>
              <el-form-item label="适用对象：" prop="useCrowd" class="margin-20">
                <!-- <el-select v-model="ruleForm.useCrowd" placeholder="请选择">
                  <el-option v-for="item in applyObjOption" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                </el-select> -->
                <el-radio-group v-model="ruleForm.useCrowd">
                  <el-radio v-for="el in applyObjOption" :key="el.value" :label="el.value">{{ el.label }}</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="人群定向：" v-if="ruleForm.useCrowd == 2" prop="" class="padding-0">
                <el-button style="width: 214px;" @click="showPeople">已设置{{ selectCount }}项筛选</el-button>
              </el-form-item>
              <el-form-item label="获取规则：" prop="integralGetStatus">
                <div>
                  <el-radio v-model="ruleForm.integralGetStatus" label="0" @change="radioEvent">不获取积分</el-radio>
                </div>
                <div class="margin-20">
                  <el-radio v-model="ruleForm.integralGetStatus" label="1">每消费</el-radio>
                  <el-input-number v-model="ruleForm.integralGet.fee" placeholder="请输入" :precision="1" :controls="false" :max="10000.0" :min="0.1" style="width: 115px"></el-input-number>
                  <label>元，获取 </label>
                  <!-- <el-input v-model="ruleForm.integralGet.integral" @blur="formatInputNumBlur($event)"></el-input> -->
                  <el-input-number v-model="ruleForm.integralGet.integral" placeholder="请输入" step-strictly  :controls="false" style="width: 115px"></el-input-number>
                  <label>积分。取整策略为</label>
                  <el-select v-model="ruleForm.integralGetStrategy" placeholder="请选择" style="width: 115px">
                    <el-option v-for="item in cateOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                  </el-select>
                  <p class="setting-tips" style="margin: 6px 0 0">例：根据消费金额计算出积分为4.3，选择「四舍五入」和「抹零」时为4积分，选择「进位制」则为5积分</p>
                </div>
              </el-form-item>
              <el-form-item label="积分冻结期：" v-if="ruleForm.integralGetStatus == 1" prop="integralGetFreezeDays">
                自获取之日起
                <el-input v-model="ruleForm.integralGetFreezeDays" @keyup.native="formatInputNum($event)" style="width: 115px"></el-input><label>天</label>
                <span class="setting-tips">仅对通过订单获取的积分生效，活动类获取的积分没有冻结期</span>
              </el-form-item>
              <el-form-item label="积分有效期：" prop="" required>
               <el-radio  v-model="ruleForm.userGeneralIntegralExpireRule" :label="1">通用积分策略有效期</el-radio>
                <el-radio v-model="ruleForm.userGeneralIntegralExpireRule"  :label="0">自定义有效期
                  <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>
                </el-radio>
                <!-- 通用积分有效期 -->
                 <div  v-if="ruleForm.userGeneralIntegralExpireRule == 1">
                  <div class="radio-cell" v-if="timeType == 1">
                    <el-radio  v-model="ruleForm.integralExpireType" label="1" @change="radioExpireType1" disabled="true">永久有效</el-radio>
                  </div>
                  <div class="radio-cell" v-else-if="timeType == 2">
                    <el-radio  v-model="ruleForm.integralExpireType" label="2" disabled="true"><label>按年失效：</label></el-radio>
                    <label>每年获取的所有积分，在</label>
                    <el-select v-model="yearYT" placeholder="请选择" style="width:120px;margin-right:20px" disabled="true">
                      <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="yearMT" placeholder="请选择" style="width:120px;margin-right:20px" disabled="true">
                      <el-option v-for="n in 12" :key="n" :label="n" :value="n"></el-option>
                    </el-select>
                    <label>月</label>
                    <el-select v-model="yearDT" placeholder="请选择" style="width:120px;margin-right:20px" disabled="true">
                      <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" v-else-if="timeType == 3">
                    <el-radio  v-model="ruleForm.integralExpireType" label="3" disabled="true"><label>按月失效：</label></el-radio>
                    <label>每月获取的所有积分，在</label>
                    <el-select v-model="mouthMT" placeholder="请选择" style="width:120px;margin-right:20px" disabled="true">
                      <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="mouthDT" placeholder="请选择" style="width:120px; margin-right:20px" disabled="true">
                      <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" v-else-if="timeType == 0 || timeType == null">
                    <el-radio  v-model="ruleForm.integralExpireType" label="0" disabled="true">
                    <label>每天获取的所有积分，在获取之日起</label></el-radio>
                    <el-input placeholder="请输入" style="width:115px" v-model="effectiveDays" @keyup.native="formatInput($event)" disabled="true"></el-input>
                    <label>天后失效</label>
                    <span style="font-size: 12px;color: #909399;line-height: 1;padding-left: 10px;">建议不超过3年(1095天)</span>
                  </div>
                  <div class="radio-cell" v-else>
                    <p style="color:red;">还未配置通用积分策略，请先配置通用积分策略再选择「通用积分策略有效期」</p>
                  </div>
                </div>
                <!-- 自定义有效期 -->
                <div class="form-child p20" v-if="ruleForm.userGeneralIntegralExpireRule == 0">
                  <div class="radio-cell mb20">
                    <el-radio  v-model="ruleForm.integralExpireType" :label="2" @change="radioExpireType1">按年失效：</el-radio>
                    <label>每年获取的所有积分，在</label>
                    <el-select v-model="yearY" placeholder="请选择" class="selectwm">
                      <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="请选择" class="selectwm">
                      <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="请选择" class="selectwm">
                      <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">按月失效：</el-radio>
                    <label>每月获取的所有积分，在</label>
                    <el-select v-model="mouthM" placeholder="请选择" class="selectwm">
                      <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="请选择" class="selectwm">
                      <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">按天失效：</el-radio>
                    <label>每天获取的所有积分，在获取之日起</label>
                    <el-input placeholder="请输入" style="width:115px" v-model="ruleForm.integralGetEffectiveDays" @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>
                </div>
              </el-form-item>
              <!-- 新增策略有效期配置 -->
              <el-form-item label="策略有效期：" prop="perpetualFlag">
                <!-- 1 永久 0 非永久 -->
                <el-radio  v-model="ruleForm.perpetualFlag" :label="1">永久有效</el-radio>
                <el-radio v-model="ruleForm.perpetualFlag"  :label="0">
                  在该时段内有效
                </el-radio>
                <div style="marginTop:10px;"><el-date-picker
                    v-if="ruleForm.perpetualFlag === 0"
                    v-model="ruleForm.perpetualDate"
                    type="datetimerange"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="timestamp"
                    :default-time="['00:00:00', '23:59:59']">
                  </el-date-picker></div>
              </el-form-item>
              <!-- <el-form-item style="bottom">
                <el-button :disabled="tpnEditBool" type="primary" @click="submitForm('ruleForm')" style="margin:13px 0 0 -220px;">保 存</el-button>
                <el-button @click="goBack">返 回</el-button>
              </el-form-item> -->
            </el-form>
            <div class="bottom">
                 <el-button :disabled="tpnEditBool" type="primary" @click="submitForm('ruleForm')" style="margin:13px 0 0 -220px;">保 存</el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- <vue-gic-footer></vue-gic-footer> -->
    <!-- 添加商品 -->
    <add-goods :goodShow="goodShow" :projectName="repProjectName" @selectGoods="selectGoods"></add-goods>
    <!-- 人群筛选器的弹框 -->
    <el-dialog title="自定义人群" :visible.sync="dialogVisiblePeople" width="980px">
      <div class="select-people">
        <vue-gic-group-people :useId="useId" :hasSearchData="hasSearchData" :sceneValue="sceneValue" ref="peopleFilter" @findFilter="findFilter" @getBackData="getBackData" @editHide="editHide" @editShow="editShow" @hideBtn="hideBtn"></vue-gic-group-people>
        <div v-show="toggleTag" class="people-btn-wrap">
          <el-row>
            <el-button @click="getData" type="primary" size="small">确定</el-button>
            <el-button @click="cancelFilter" size="small">取消</el-button>
          </el-row>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-row>
          <el-button @click="dialogVisiblePeople = false">取 消</el-button>
          <el-button type="primary" @click="getPeopleData">确 定</el-button>
        </el-row>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import topNavNew from 'components/nav/navNew';
import addGoods from 'components/memberShip/add-goods';
import Treeselect from '@riophae/vue-treeselect';
// import the styles
import '@riophae/vue-treeselect/dist/vue-treeselect.css';

import showMsg from '@/common/js/showmsg';
import errMsg from '@/common/js/error';
import { postRequest, postJson } from '@/api/api';
import strLength from '@/common/js/strlen';
import { log } from '@/utils/index.js';
import wmMixins from './strategy.js';

const timeStramp = {
  year: new Date().getFullYear(),
  month: new Date().getMonth(),
  day: new Date().getDate()
};

export default {
  name: 'addPointSytem',
  mixins: [wmMixins],
  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 {
      yearYT: '', //按年失效 年
      yearMT: '', //按年失效 月
      yearDT: '', //按年失效 日
      mouthMT: '', //按月失效 月
      mouthDT: '', //按月失效 月
      effectiveDays: undefined,
      timeType: '',
      timeRuleType: '',
      dayList: dayList(),
      mouthList: mouthList(),
      mouthM: '', //按月失效 月
      mouthD: '', //按月失效 月
      yearList: yearList(),
      yearY: '', //按年失效 年
      yearM: '', //按年失效 月
      yearD: '', //按年失效 日
      repProjectName: 'gic-clique',
      navpath: [
        {
          name: '集团管理',
          path: ''
        },
        {
          name: '会员制度',
          path: ''
        },
        {
          name: '积分制度',
          path: '/pointSystem'
        },
        {
          name: '新增积分获取策略',
          path: ''
        }
      ],
      // 添加商品弹窗
      goodShow: false,
      // 输入字限制
      inputFlagNum: 20,

      // 门店
      StoreOptions: [
        {
          label: '所有门店',
          value: '1'
        },
        {
          label: '门店分组',
          value: '2'
        },
        {
          label: '部分门店',
          value: '3'
        }
      ],
      StoreTypeOptions: [
        {
          label: '所有门店',
          value: '-1'
        },
        {
          label: '自营',
          value: '0'
        },
        {
          label: '联营',
          value: '1'
        },
        {
          label: '加盟',
          value: '2'
        },
        {
          label: '代销',
          value: '3'
        },
        {
          label: '托管',
          value: '4'
        }
      ],
      applyGoods: [
        {
          label: '所有商品',
          value: '1'
        }
        // {
        //   label: '按商品品牌',
        //   value: '2',
        // },
        // {
        //   label: '按商品品类',
        //   value: '3',
        // },
        // {
        //   label: '按单件商品',
        //   value: '4',
        // },
      ],
      // tree
      openOnFocus: true,
      alwaysOpen: false,
      goodsOpen: false,
      wxOpen: false,
      valueConsistsOf: 'ALL',
      treeOptions: [],
      storeNormalizer(node) {
        return {
          id: node.storeGroupId,
          label: node.storeGroupName,
          children: node.children
        };
      },

      // 门店列表
      storeListOptions: [],
      // 适用商品
      goodsTreeOptions: [],

      // wxTreeOptions
      wxTreeOptions: [],
      // 第三方下拉
      allShopOption: [
        {
          label: '所有店铺', // 就是所有门店
          value: '1'
        }
      ],
      allGoodOption: [
        {
          label: '所有商品',
          value: '1'
        }
      ],
      // 微盟渠道
      wMShopOption: [
        {
          label: '所有店铺', // 就是所有门店
          value: '1'
        }
      ],
      wMGoodOption: [
        {
          label: '所有商品',
          value: '1'
        }
      ],
      // 商户
      mechantOption: [],
      // 适用对象
      applyObjOption: [
        {
          label: '所有会员',
          value: '1'
        },
        {
          label: '自定义人群',
          value: '2'
        }
      ],
      // 长度
      cateNameLength: 0,

      ruleForm: {
        userGeneralIntegralExpireRule: 1,
        integralExpireType: '0', //积分有效期类型 0 未默认滚动到期 1永久 2 按年失效 3按月失效
        integralExpireRule: '', //积分有效期规则 年 x(年),x(月),x(日，为0标识月末)  月,x(月),x(日，为0标识月末)
        // 积分获取规则
        integralStrategyId: '', //策略id
        enterpriseId: '',
        strategyName: '', //策略名称
        strategyType: 1, // 策略类型 1消费积分 2积分抵现
        useCrowd: '1', // 策略类型 1所有 2人群筛选
        crowdJson: '', //人群筛选器内容
        integralGetStatus: '1', // 积分获取开启 1是0否
        integralGet: { fee: '1', integral: '1' },
        integralGetStrategy: '1', // 取整策略 1四舍五入 2抹零 3向上取整
        integralGetFreezeDays: 1, // 获取积分冻结天数
        integralGetEffectiveDays: 1, // 获取积分有效天
        integralUseStatus: '0', // 积分抵现开启 1是0否
        // integralUse: { fee: undefined, integral: undefined }, // 积分抵现 {fee:5,integral:5}
        perpetualFlag: 1,
        channelList: [
          {
            integralStrategyChannelId: '', //id
            enterpriseId: '',
            integralStrategyId: '', //策略id
            channelType: '3', //渠道类型 1微信 3:线下 5淘宝 6京东 7唯品会 8天猫
            openStatus: false, //渠道配置是否启用 1启用 0停用
            channelRelationEnterpriseType: '1', // 策略关联企业 1所有企业 2部分企业
            channelRelationStoreType: '1', //策略关联门店类型 1所有门店 2门店分组 3部分门店
            channelStoreType: '-1', // 策略选择门店类型 （-1:所有 0:自营 1:联营 2:加盟,3代销4托管）
            channelRelationProType: '1', // 策略关联商品类型 1所有商品 2商品品牌 3商品类目 4部分商品
            integralUseDiscountControl: '1', // 折扣控制 1所有折扣商品适用 2折扣范围
            integralUseDiscountControlUpper: undefined,
            integralUseDiscountControlLower: undefined,
            useProportionalRestriction: '0.0', // 抵现比例限制
            strategyGoodsRelationIdArr: [], // 商品
            storeRelationIdArr: [], //门店
            enterpriseRelationIdArr: [] //商户
          },
          {
            integralStrategyChannelId: '', //id
            enterpriseId: '',
            integralStrategyId: '', //策略id
            channelType: '1', //渠道类型 1微信 3:线下 5淘宝 6京东 7唯品会 8天猫
            openStatus: false, //渠道配置是否启用 1启用 0停用
            channelRelationEnterpriseType: '1', // 策略关联企业 1所有企业 2部分企业
            channelRelationStoreType: '1', //策略关联门店类型 1所有门店 2门店分组 3部分门店
            channelStoreType: '-1', // 策略选择门店类型 （-1:所有 0:自营 1:联营 2:加盟,3代销4托管）
            channelRelationProType: '1', // 策略关联商品类型 1所有商品 2商品品牌 3商品类目 4部分商品
            integralUseDiscountControl: '1', // 折扣控制 1所有折扣商品适用 2折扣范围
            integralUseDiscountControlUpper: undefined,
            integralUseDiscountControlLower: undefined,
            useProportionalRestriction: '0.0', // 抵现比例限制
            goodsRelationIdArr: [], // 复制的商品
            strategyGoodsRelationIdArr: [], // 商品
            storeRelationIdArr: [], //门店
            enterpriseRelationIdArr: [] //商户
          },
          {
            integralStrategyChannelId: '', //id
            enterpriseId: '',
            integralStrategyId: '', //策略id
            channelType: '9', //渠道类型 1微信 3:线下 5淘宝 6京东 7唯品会 8天猫
            openStatus: false, //渠道配置是否启用 1启用 0停用
            channelRelationEnterpriseType: '1', // 策略关联企业 1所有企业 2部分企业
            channelRelationStoreType: '1', //策略关联门店类型 1所有门店 2门店分组 3部分门店
            channelStoreType: '-1', // 策略选择门店类型 （-1:所有 0:自营 1:联营 2:加盟,3代销4托管）
            channelRelationProType: '1', // 策略关联商品类型 1所有商品 2商品品牌 3商品类目 4部分商品
            integralUseDiscountControl: '1', // 折扣控制 1所有折扣商品适用 2折扣范围
            integralUseDiscountControlUpper: undefined,
            integralUseDiscountControlLower: undefined,
            useProportionalRestriction: '0.0', // 抵现比例限制
            strategyGoodsRelationIdArr: [], // 商品
            storeRelationIdArr: [], //门店
            enterpriseRelationIdArr: [] //商户
          },
          {
            integralStrategyChannelId: '', //id
            enterpriseId: '',
            integralStrategyId: '', //策略id
            channelType: '8', //渠道类型 1微信 3:线下 5淘宝 6京东 7唯品会 8天猫
            openStatus: false, //渠道配置是否启用 1启用 0停用
            channelRelationEnterpriseType: '1', // 策略关联企业 1所有企业 2部分企业
            channelRelationStoreType: '1', //策略关联门店类型 1所有门店 2门店分组 3部分门店
            channelStoreType: '-1', // 策略选择门店类型 （-1:所有 0:自营 1:联营 2:加盟,3代销4托管）
            channelRelationProType: '1', // 策略关联商品类型 1所有商品 2商品品牌 3商品类目 4部分商品
            integralUseDiscountControl: '1', // 折扣控制 1所有折扣商品适用 2折扣范围
            integralUseDiscountControlUpper: undefined,
            integralUseDiscountControlLower: undefined,
            useProportionalRestriction: '0.0', // 抵现比例限制
            strategyGoodsRelationIdArr: [], // 商品
            storeRelationIdArr: [], //门店
            enterpriseRelationIdArr: [] //商户
          },
          {
            integralStrategyChannelId: '', //id
            enterpriseId: '',
            integralStrategyId: '', //策略id
            channelType: '11', //渠道类型 1微信 3:线下 5淘宝 6京东 7唯品会 8天猫
            openStatus: false, //渠道配置是否启用 1启用 0停用
            channelRelationEnterpriseType: '1', // 策略关联企业 1所有企业 2部分企业
            channelRelationStoreType: '1', //策略关联门店类型 1所有门店 2门店分组 3部分门店
            channelStoreType: '-1', // 策略选择门店类型 （-1:所有 0:自营 1:联营 2:加盟,3代销4托管）
            channelRelationProType: '1', // 策略关联商品类型 1所有商品 2商品品牌 3商品类目 4部分商品
            integralUseDiscountControl: '1', // 折扣控制 1所有折扣商品适用 2折扣范围
            integralUseDiscountControlUpper: undefined,
            integralUseDiscountControlLower: undefined,
            useProportionalRestriction: '0.0', // 抵现比例限制
            strategyGoodsRelationIdArr: [], // 商品
            storeRelationIdArr: [], //门店
            enterpriseRelationIdArr: [] //商户
          },
          {
            integralStrategyChannelId: '', //id
            enterpriseId: '',
            integralStrategyId: '', //策略id
            channelType: '10', //渠道类型 1微信 3:线下 5淘宝 6京东 7唯品会 8天猫
            openStatus: false, //渠道配置是否启用 1启用 0停用
            channelRelationEnterpriseType: '1', // 策略关联企业 1所有企业 2部分企业
            channelRelationStoreType: '1', //策略关联门店类型 1所有门店 2门店分组 3部分门店
            channelStoreType: '-1', // 策略选择门店类型 （-1:所有 0:自营 1:联营 2:加盟,3代销4托管）
            channelRelationProType: '1', // 策略关联商品类型 1所有商品 2商品品牌 3商品类目 4部分商品
            integralUseDiscountControl: '1', // 折扣控制 1所有折扣商品适用 2折扣范围
            integralUseDiscountControlUpper: undefined,
            integralUseDiscountControlLower: undefined,
            useProportionalRestriction: '0.0', // 抵现比例限制
            strategyGoodsRelationIdArr: [], // 商品
            storeRelationIdArr: [], //门店
            enterpriseRelationIdArr: [] //商户
          }
        ],
        perpetualDate: [
          new Date(timeStramp.year, timeStramp.month, timeStramp.day, 0, 0, 0).getTime(),
          new Date(timeStramp.year, timeStramp.month, timeStramp.day, 23, 59, 59).getTime()
        ]
      },
      rules: {
        strategyName: { required: true, message: '请输入策略名称', trigger: 'blur' },
        useCrowd: { required: true, message: '请选择适用对象', trigger: 'blur' },
        integralGetStatus: { required: true, message: '请选择获取规则', trigger: 'blur' },
        integralGetFreezeDays: { required: true, message: '请输入积分冻结期', trigger: 'blur' },
        userGeneralIntegralExpireRule: { required: true, message: '请输入有效期类型', trigger: 'blur' },
        perpetualFlag: { required: true, message: '请选择策略有效期', trigger: 'blur' }
      },
      cateOptions: [
        {
          value: '1',
          label: '四舍五入'
        },
        {
          value: '2',
          label: '抹零'
        },
        {
          value: '3',
          label: '进位制'
        }
      ],
      // 门店  新
      uuid: '', // 新增传空，编辑必传,
      options: [0, 1, 2, 3, 4, 5], // 0 全部 1 门店类型 2门店标签 3 门店区域 4 门店分组 5 部分门店
      isAdd: true,
      scencs: 'integral',
      wmuuid: '', // 微盟

      /* 人群筛选器 */
      dialogVisiblePeople: false,
      sceneValue: 'member', // 场景值
      useId: '',
      searchParams: '',
      hasSearchData: '', // 当前页回显的数据(接口返回)
      toggleTag: false,
      selectCount: 0,
      // 太平鸟标识
      tpnEditBool: false,
      tpnEnterpriseId: 'ff808081671d3ceb01672adebf4e6149'
    };
  },

  methods: {
    // 获取通用积分策略
    getPointInfo() {
      var that = this
      postRequest('/api-admin/get-member-integral-setting',{requestProject: that.projectName})
        .then((res) => {
          var resData = res.data
          if(resData.errorCode == 0) {
            this.timeType = resData.result.memberIntegral.integralExpireType;
            this.timeRuleType = resData.result.memberIntegral.integralExpireRule;
            if(this.timeType ==2) {
              this.yearYT = Number(this.timeRuleType[0])
              this.yearMT = Number(this.timeRuleType[2])
              this.yearDT = Number(this.timeRuleType[4])
            }else if(this.timeType == 3) {
              this.mouthMT = Number(this.timeRuleType[0])
              this.mouthDT = Number(this.timeRuleType[2])
            } else if (this.timeType == 0 || this.timeType == null) {
              this.effectiveDays = resData.result.memberIntegral.effectiveTime;
            }
          }
        })
    },
    radioEventN(n) {
      this.ruleForm.channelList[n].integralUseDiscountControlLower = undefined;
      this.ruleForm.channelList[n].integralUseDiscountControlUpper = undefined;
    },
    radioEvent() {
      this.ruleForm.integralGet.fee = undefined;
      this.ruleForm.integralGet.integral = 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.integralGetEffectiveDays = '';
      }else if (e==2) {
        this.mouthM='';
        this.mouthD='';
        this.ruleForm.integralGetEffectiveDays = '';
      } else if (e == 3) {
        this.yearY='';
        this.yearM='';
        this.yearD='';
        this.ruleForm.integralGetEffectiveDays = '';
      }
    },
    onStoreChange(item) {
      if (item.channelType == 3) {
        this.uuid = '';
      } else if (item.channelType == 9) {
        this.wmuuid = '';
      }
      item.channelRelationProType = '1';
    },
    // 返回
    goBack() {
      this.$router.go(-1);
    },

    // 路由跳转
    changeRoute(route) {
      this.$router.push(route);
    },

    // input focus
    inputFocus(obj) {
      let that = this;
      that.tempData = obj;
    },
    formatInputNum(e) {
      let that = this;
      that.ruleForm.integralGetEffectiveDays = strLength.getCharVal(String(that.ruleForm.integralGetEffectiveDays).replace(/[^\d]/g, ''), 4);
      that.ruleForm.integralGetFreezeDays = strLength.getCharVal(String(that.ruleForm.integralGetFreezeDays).replace(/[^\d]/g, ''), 4);

      // that.ruleForm.integralGet.fee = strLength.getCharVal(String(that.ruleForm.integralGet.fee).replace(/[^\.\d]/g,''),6)
      that.ruleForm.integralGet.integral = strLength.getCharVal(String(that.ruleForm.integralGet.integral).replace(/[^\d]/g, undefined), 8);
    },

    async checkListValue(data) {
      let obj = {
        flag: true,
        text: ''
      };
      if (!!data.channelList.length) {
        for (let i = 0; i < data.channelList.length; i++) {
          if (!!data.channelList[i].openStatus) {
            if (!!data.channelList[i].openStatus && data.channelList[i].integralUseDiscountControl == 2) {
              if (!data.channelList[i].integralUseDiscountControlUpper || !data.channelList[i].integralUseDiscountControlLower) {
                obj.flag = false;
                obj.text = '请填写折扣';
              }
              if (parseInt(data.channelList[i].integralUseDiscountControlUpper) > 10 || parseInt(data.channelList[i].integralUseDiscountControlLower) > 10 || Number(data.channelList[i].integralUseDiscountControlUpper) <= Number(data.channelList[i].integralUseDiscountControlLower)) {
                obj.flag = false;
                obj.text = '折扣格式有误';
              }
            }
            if (data.channelList[i].channelType == 1 && !data.channelList[i].enterpriseRelationIdArr.length) {
              obj.flag = false;
              obj.text = '请选择达摩微商城的商户';
              return obj;
            }
            if (data.channelList[i].channelType == 9 && !data.channelList[i].enterpriseRelationIdArr.length) {
              obj.flag = false;
              obj.text = '请选择微盟渠道的商户';
              return obj;
            }
            if (data.channelList[i].channelType == 8 && !data.channelList[i].enterpriseRelationIdArr.length) {
              obj.flag = false;
              obj.text = '请选择天猫渠道的商户';
              return obj;
            }
            if (data.channelList[i].channelType == 11 && !data.channelList[i].enterpriseRelationIdArr.length) {
              obj.flag = false;
              obj.text = '请选择抖音渠道的商户';
              return obj;
            }
            if (data.channelList[i].channelType == 10 && !data.channelList[i].enterpriseRelationIdArr.length) {
              obj.flag = false;
              obj.text = '请选择其他渠道的商户';
              return obj;
            }
            if (data.channelList[i].channelType == 3 && data.channelList[i].enterpriseRelationIdArr.length > 0) {
              const storeGroupDom = this.$refs.storeGroup;
              let flag = null;
              if (storeGroupDom instanceof Array) {
                flag = await this.$refs.storeGroup[0].isStoreSave();
              } else {
                flag = await this.$refs.storeGroup.isStoreSave();
              }
              if (!flag) {
                obj.flag = false;
                obj.text = '请选择门店';
              }
            }
            if (data.channelList[i].channelType == 9 && this.isJinHua) {
              const storeGroupDom = this.$refs.wmstoreGroup;
              let flag = null;
              if (storeGroupDom instanceof Array) {
                flag = await this.$refs.wmstoreGroup[0].isStoreSave();
              } else {
                flag = await this.$refs.wmstoreGroup.isStoreSave();
              }
              if (!flag) {
                obj.flag = false;
                obj.text = '请选择门店';
              }
            }
          }
        }
      }
      return obj;
    },

    // 保存
    submitForm(formName) {
      let that = this;
      if (!that.tpnEditBool) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            // 处理数据
            let data = JSON.parse(JSON.stringify(that.ruleForm));
            if (!data.strategyName) {
              showMsg.showmsg('请填写策略名称', 'error');
              return;
            }
            let flag = !data.integralGet.fee || String(data.integralGet.integral) == '';
            if (data.integralGetStatus == 1 && flag) {
              showMsg.showmsg('请填写获取规则', 'error');
              return;
            }
            if (data.integralGetStatus == 1) {
              if (!Number(data.integralGet.fee)) {
                showMsg.showmsg('获取规则中的消费金额不能为0', 'error');
                return;
              }
              if (!Number(data.integralGet.integral)) {
                showMsg.showmsg('获取规则中的获取积分不能为0', 'error');
                return;
              }
            }
            if (data.integralGetStatus == 1 && !Number(data.integralGetFreezeDays) && data.integralGetFreezeDays != '0') {
              showMsg.showmsg('请填写积分冻结期', 'error');
              return;
            }
            if (data.userGeneralIntegralExpireRule == 0 && data.integralExpireType ==0  && !Number(data.integralGetEffectiveDays)) {
              showMsg.showmsg('请填写积分有效期', 'error');
              return;
            }
            that.checkListValue(data).then(res => {
              if (!res.flag) {
                showMsg.showmsg(res.text, 'error');
                return;
              } else {
                // 自定义人群
                if (data.useCrowd == 2 && this.selectCount < 1) {
                  showMsg.showmsg('请选择人群定向', 'error');
                  return;
                }
                // 设置开启状态 1-->true
                data.channelList.forEach(function(ele, index) {
                  ele.openStatus = ele.openStatus == true ? 1 : 0;
                  if (ele.channelType == 1) {
                    ele.strategyGoodsRelationIdArr = ele.goodsRelationIdArr;
                    delete ele.goodsRelationIdArr;
                  }
                  if (!ele.enterpriseRelationIdArr || !ele.enterpriseRelationIdArr.length) {
                    ele.enterpriseRelationIdArr = [];
                  }
                  if (!ele.storeRelationIdArr || !ele.storeRelationIdArr.length) {
                    ele.storeRelationIdArr = [];
                  }
                  if (!ele.strategyGoodsRelationIdArr || !ele.strategyGoodsRelationIdArr.length) {
                    ele.strategyGoodsRelationIdArr = [];
                  }
                  if (ele.channelType == '3') {
                    ele.channelRelationStoreType = '1';
                    ele.channelStoreType = '-1';
                    ele.storeControlId = that.uuid;
                  }
                  if (ele.channelType == '9') {
                    ele.storeControlId = that.wmuuid;
                  }
                });
                data.integralGet.fee = parseInt(data.integralGet.fee * 10);
                data.integralGet.integral = parseInt(data.integralGet.integral * 10);
                data.integralGet = JSON.stringify(data.integralGet);

                // 3.0_特殊策略新增有效期配置
                if (data.perpetualFlag === 1) {
                  // 永久
                  // perpetualFlag 是否永久  0 非永久  1永久'
                  // startValidTime 有效期时间开始(毫秒时间戳)
                  // endValidTime  有效时间结束（毫秒时间戳）
                } else {
                  // 时间区间
                  // if (data.perpetualDate[0].indexOf('Z') > -1) {
                  //   // 说明第一次没有动过
                  //   data.startValidTime = new Date(this.transUTCTime(data.perpetualDate[0]) + ' 00:00').getTime();
                  //   data.endValidTime = new Date(this.transUTCTime(data.perpetualDate[1]) + ' 23:59').getTime();
                  // } else {
                  //   data.startValidTime = new Date(data.perpetualDate[0].slice(0, -3)).getTime();
                  //   data.endValidTime = new Date(data.perpetualDate[1].slice(0, -3)).getTime();
                  // }
                  data.startValidTime = data.perpetualDate[0];
                  data.endValidTime = data.perpetualDate[1];
                }
                delete data.perpetualDate;
                if(data.userGeneralIntegralExpireRule == 1) {
                  data.integralExpireType = this.timeType
                  if(this.timeType==0 || this.timeType == null){
                    data.integralGetEffectiveDays = this.effectiveDays
                  }else {
                    data.integralExpireRule = this.timeRuleType
                  }
                }else if (data.userGeneralIntegralExpireRule == 0) {
                  if(data.integralExpireType == 0) {
                    data.integralExpireRule = ''
                  }else if(data.integralExpireType == 1) {
                    data.integralExpireRule = ''
                    data.integralGetEffectiveDays = ''
                  } else if(data.integralExpireType == 2) {
                    data.integralExpireRule = `${this.yearY},${this.yearM},${this.yearD}`
                    data.integralGetEffectiveDays = ''
                  }else if(data.integralExpireType == 3) {
                    data.integralExpireRule = `${this.mouthM},${this.mouthD}`
                    data.integralGetEffectiveDays = ''
                  }
                }
                that.saveForm(data);
              }
            });
          } else {
            log('error submit!!');
            return false;
          }
        });
      }
    },

    // 保存数据
    saveForm(data) {
      let that = this;
      let para = data;
      postJson('/api-admin/save-member-integral-strategy', para)
        .then(res => {
          log(res.data.result);
          let resData = res.data;
          if (resData.errorCode == 0) {
            that.$message({
              message: '保存成功',
              type: 'success'
            });
            that.changeRoute('/pointSystem');
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          log(error);
        });
    },

    // 更新数据
    updateData() {
      let that = this;
      // that.ruleForm.integralGet = JSON.parse(that.ruleForm.integralGet)
      that.ruleForm.integralGet.fee = parseInt(that.ruleForm.integralGet.fee / 10);
      that.ruleForm.integralGet.integral = parseInt(that.ruleForm.integralGet.integral / 10);
    },

    // 树形结构
    toggle(flag) {
      let that = this;
      that.treeFlag = flag;
      if (flag == 'store') {
        that.alwaysOpen = true;
        log(that.alwaysOpen);
      }
      if (flag == 'brand') {
        that.goodsOpen = true;
      }
      if (flag == 'wx') {
        that.wxOpen = true;
      }
      document.addEventListener('click', that.hidePanel, false);
    },

    hidePanel(e) {
      let that = this;
      log(that.$refs.treeinput, e.target.className);
      if (typeof e.target.className == 'object') {
        return;
      }
      let tag =
        e.target.className != 'span-txt' &&
        e.target.className != 'vue-treeselect__list' &&
        e.target.className != 'vue-treeselect__label' &&
        !e.target.className.includes('vue-treeselect__list-item vue-treeselect__indent-level') &&
        e.target.className != 'vue-treeselect__minus-mark' &&
        e.target.className != 'vue-treeselect__option' &&
        e.target.className != 'vue-treeselect__option vue-treeselect__option--highlight' &&
        !e.target.className.includes('vue-treeselect__checkbox vue-treeselect__checkbox--') &&
        e.target.className != 'vue-treeselect__option-arrow-placeholder' &&
        e.target.className != 'el-form demo-ruleForm' &&
        e.target.className != 'vue-treeselect__option vue-treeselect__option--selected vue-treeselect__option--highlight' &&
        e.target.className != 'vue-treeselect__list-item vue-treeselect__indent-level-1' &&
        e.target.className != 'vue-treeselect__list-item vue-treeselect__indent-level-0' &&
        e.target.className != 'vue-treeselect__checkbox-container' &&
        e.target.className != 'vue-treeselect__option-arrow-container' &&
        e.target.className != 'vue-treeselect__option-arrow vue-treeselect__option-arrow--rotated';
      log(tag);
      if (tag) {
        if (that.treeFlag == 'store') {
          that.alwaysOpen = false;
        }
        if (that.treeFlag == 'brand') {
          that.goodsOpen = false;
        }
        if (that.treeFlag == 'wx') {
          that.wxOpen = false;
        }
      }
    },

    // 搜索后出现下拉列表
    // 点击
    searchFocus(index, item) {
      log(index, item);
    },
    // 搜索
    remoteMethod(query) {
      let that = this;
      log('query:', query);

      if (query !== '') {
        // 获取搜索列表数据
        that.getStoreList(query);
      } else {
        that.storeListOptions = [];
      }
    },

    // 选择节点的方法
    selectStore(e, item) {
      log(e);
    },

    // 获取门店列表
    getStoreList(query) {
      let that = this;
      log(query);
      let para = {
        searchParam: query,
        flag: null,
        requestProject: that.repProjectName
      };

      postRequest('/api-plug/query-store-by-code-name', para)
        .then(res => {
          log(res, res.data, res.data.errorCode);
          let resData = res.data;
          if (resData.errorCode == 0) {
            resData.result.forEach(function(ele, index) {
              ele.id = ele.storeId;
              ele.value = ele.storeName;
              ele.key = ele.storeId;
            });
            that.storeListOptions = resData.result;
            return;
          }

          that.$message.error({
            duration: 1000,
            message: resData.message
          });
        })
        .catch(function(error) {
          log(error);
          // that.toLogin()
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    // 获取门店分组
    getStoreGroup() {
      let that = this;
      let para = {};

      postRequest('/api-admin/get-clique-storegroup', para)
        .then(res => {
          log(res.data.result);
          let resData = res.data;
          if (resData.errorCode == 0) {
            that.treeOptions = resData.result;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          log(error);

          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    // 输入
    toInput: function(value) {
      let that = this;
      let temp = strLength.getByteVal(value.target.value, that.inputFlagNum);
      that.ruleForm.strategyName = temp.trim();
      that.cateNameLength = strLength.getZhLen(that.ruleForm.strategyName);
    },
    selStore(e, index, item) {
      item.storeRelationIdArr = [];
    },

    // 微信
    selectWx(e, index, item) {
      let that = this;
      item.strategyGoodsRelationIds = item.goodsRelationIds;
      let data = that.ruleForm.channelList[index];
      data.strategyGoodsRelationIds = [];
      data.goodsRelationIds.forEach(function(ele, index) {
        data.strategyGoodsRelationIds.push(ele);
      });
    },
    // 线下渠道选择商品类别
    changeGood(e) {
      let that = this;
      log('线下渠道选择商品类别:', e);
      if (e == 2) {
        that.getGoodsBrand();
      }
      if (e == 3) {
        that.getGoodsCategory();
      }
    },

    // 获取商品品牌
    getGoodsBrand() {
      let that = this;
      let para = {};
      postRequest('/api-admin/', para)
        .then(res => {
          log(res.data.result);
          let resData = res.data;
          if (resData.errorCode == 0) {
            let data = resData.result;
            that.goodsTreeOptions = data;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          log(error);

          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    // 获取商品分类
    getGoodsCategory() {
      let that = this;
      let para = {};
      postRequest('/api-admin/', para)
        .then(res => {
          log(res.data.result);
          let resData = res.data;
          if (resData.errorCode == 0) {
            let data = resData.result;
            that.goodsTreeOptions = data;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          log(error);

          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    // 子组件显示方法
    showGoodsDialog() {
      let that = this;
      log('show');
      that.goodShow = true;
    },

    // 子组件触发方法
    selectGoods(val) {
      let that = this;
      log(val);
      that.goodShow = false;
    },

    // 获取商户列表
    getCliqueInfo() {
      let that = this;
      let para = {};
      postRequest('/api-admin/list-enterprise', para)
        .then(res => {
          log(res.data);
          let resData = res.data;
          if (resData.errorCode == 0) {
            let data = resData.result.listEnterprise;
            data.forEach(function(ele, index) {
              ele.label = ele.brandName;
              ele.value = ele.enterpriseId;
            });
            that.mechantOption = data;
            log('商户列表:', that.mechantOption);
            // showMsg.showmsg('设置成功','success')

            // that.ruleForm.channelList[0].enterpriseRelationIdArr = [data[0].enterpriseId];
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          log(error);

          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    // 选择人群筛选器
    showPeople() {
      this.dialogVisiblePeople = true;
    },
    /* 人群筛选器 start */
    getData() {
      // 父组件调用子组件方法,触发父组件事件
      this.$refs.peopleFilter.confirmSet();
    },
    findFilter(value) {
      // 子组件触发父组件事件,返回过滤条件数据
      log(value);
      this.ruleForm.crowdJson = value;
      this.searchParams = value;
      if (this.ruleForm.crowdJson) {
        let arr = JSON.parse(this.ruleForm.crowdJson);
        this.selectCount = 0;
        if (arr.list) {
          arr.list.forEach(item => {
            this.selectCount += item.list.length;
          });
        }
      }
    },
    cancelFilter() {
      this.$refs.peopleFilter.cancelSet();
    },
    getBackData(val) {
      // log(val);
      this.ruleForm.selectorParams = val;
    },
    // 隐藏保存按钮和确认按钮  (子组件会调用)
    hideBtn() {
      let that = this;
      that.toggleTag = false;
    },
    // 显示编辑,保存按钮隐藏,确认按钮显示 (子组件会调用)
    editShow() {
      this.toggleTag = true;
    },
    editHide() {
      this.toggleTag = false;
    },
    getPeopleData() {
      // 筛选器 弹框的确认按钮
      let that = this;
      that.$refs.peopleFilter.confirmSet();
      setTimeout(_ => {
        if (that.searchParams) {
          that.lsSaveBtn(that.searchParams);
        }
      }, 500);
    },
    // 人群筛选器弹框的确定按钮  临时保存
    lsSaveBtn(searchParams) {
      postRequest('/api-admin/get-screen-detail-param', {
        requestProject: this.repProjectName,
        tempBusinessId: this.tempBusinessId ? this.tempBusinessId : '',
        detailParams: searchParams
      })
        .then(res => {
          if (res.data.errorCode == 0) {
            this.tempBusinessId = res.data.result;
            this.useId = res.data.result;
            this.dialogVisiblePeople = false;
            this.searchParams = '';
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch(err => {
          log(err);
        });
    },
    /* end */
    // 判断是否是太平鸟
    getLoginInfo() {
      let that = this;
      let param = {};
      postRequest('/api-auth/get-login-user-info', param)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 0) {
            if (resData.result.enterpriseId == that.tpnEnterpriseId) {
              that.tpnEditBool = true;
            }
          } else {
            errMsg.errorMsg(resData);
          }
        })
        .catch(function(error) {
          log(error);
        });
    }
  },
  components: {
    topNavNew,
    Treeselect,
    addGoods
  },
  created() {
    // this.selectReplayStyle()
    log('create');
    this.getPointInfo();
  },
  beforeMount() {
    log('beforeMount');
  },
  mounted() {
    let that = this;
    // 获取商户列表
    that.getCliqueInfo();

    // 获取门店分组
    that.getStoreGroup();
    that.getLoginInfo();
  }
};
</script>
<style lang="scss" scoped>
.selectwm {
  width:120px;
  margin:0 10px;
}
.mb20 {
  margin-bottom: 20px;
}
.bottom{
  position: fixed;
  bottom: 0px;
  left: 200px;
  width: 100%;
  height: 55px;
  text-align: center;
  background: #FFFFFF;
  box-shadow: 1px -2px 8px 0px rgba(220, 223, 230, 0.6);
}
.el-radio {
  margin-right: 0;
}
.setting-tips {
  margin-left: 16px;
  font-size: 12px;
  font-weight: 400;
  color: #909399;
  line-height: 17px;
}
.attention-wrap {
  padding: 20px;
  background: #fff;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  .item-label {
    font-size: 14px;
    color: #606266;
    margin-bottom: 30px;
    span {
      display: inline-block;
      width: 80px;
    }
  }

  .vue-treeselect {
    display: inline-block;
    vertical-align: top;
    width: 300px;
  }
  // .attention-content-wrap {
  // }
}

.form-wrap {
  .el-input {
    width: 115px;
    padding: 0 10px;
    &.w-300 {
      width: 300px;
    }
    &.w-340 {
      width: 340px;
    }
  }

  /deep/ .input-label {
    position: absolute;
    left: 303px;
    color: #ccc;
    font-size: 12px;
  }

  .el-select {
    vertical-align: top;
  }

  .span-txt {
    position: absolute;
    z-index: 2;
    width: 300px;
    text-align: center;
  }

  .padding-0 {
    padding: 0;
  }

  .form-child {
    padding: 20px;
    background: #f5f6f9;
    margin-top: 20px;
    box-sizing: border-box;
  }

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

  .tinymce-wrap {
    width: 780px;
  }
}

/*树形*/
.vue-treeselect /deep/ {
  /deep/ .vue-treeselect__control {
    height: 30px;
    /*line-height: 36px;*/
    cursor: pointer;
  }

  .vue-treeselect__placeholder {
    line-height: 30px;
    font-size: 12px;
  }

  .vue-treeselect__multi-value-item-container,
  .vue-treeselect__multi-value {
    line-height: 1;
    height: 0;
    opacity: 0;
  }

  span.vue-treeselect__multi-value-label {
    line-height: 1;
  }

  .vue-treeselect__multi-value-item {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    background-color: #f0f2f5;
    color: #909399;
  }

  .vue-treeselect__value-remove {
    color: #909399;
  }

  &:not(.vue-treeselect--disabled) .vue-treeselect__multi-value-item:not(.vue-treeselect__multi-value-item-disabled):hover {
    background-color: #f0f2f5;
    color: #909399;
  }

  .vue-treeselect--searchable:not(.vue-treeselect--disabled) .vue-treeselect__value-container {
    cursor: pointer;
  }

  .vue-treeselect__x-container {
    display: none;
  }

  .vue-treeselect__control-arrow {
    display: none;
  }

  .vue-treeselect__control-arrow-container {
    position: relative;
  }
  /deep/ .vue-treeselect__value-container {
    line-height: 30px;
  }

  /deep/.vue-treeselect__control-arrow-container:after,
  .vue-treeselect__control-arrow-container:before {
    border: 6px solid transparent;
    border-left: 6px solid #fff;
    width: 0;
    height: 0;
    position: absolute;
    top: 49%;
    left: 50%;
    margin-left: -6px;
    content: ' ';
    margin-top: -3px;
    -webkit-transform: rotate(90deg);
    -moz-transform: rotate(90deg);
    -o-transform: rotate(90deg);
    transform: rotate(90deg);
    -webkit-transition: -webkit-transform 0.3s;
    transition: -webkit-transform 0.3s;
    transition: transform 0.3s;
    transition: transform 0.3s, -webkit-transform 0.3s;
    transition: transform 0.3s, -webkit-transform 0.3s;
  }

  /deep/ .vue-treeselect__control-arrow-container:before {
    border-left-color: #c0c4cc;
    top: 52%;
  }

  &.vue-treeselect--focused .vue-treeselect__control-arrow-container:after,
  &.vue-treeselect--focused .vue-treeselect__control-arrow-container:before {
    margin-top: -6px;
    -webkit-transform: rotateZ(-90deg);
    -moz-transform: rotateZ(-90deg);
    -o-transform: rotateZ(-90deg);
    transform: rotateZ(-90deg);
    -webkit-transition: -webkit-transform 0.3s;
    transition: -webkit-transform 0.3s;
    transition: transform 0.3s;
    transition: transform 0.3s, -webkit-transform 0.3s;
    transition: transform 0.3s, -webkit-transform 0.3s;
  }

  &.vue-treeselect--focused .vue-treeselect__control-arrow-container:before {
    border-left-color: #c0c4cc;
    top: 47%;
  }

  .vue-treeselect--has-value .vue-treeselect__multi-value {
    margin-bottom: 0;
  }
}
/*人群筛选器*/
.select-people {
  max-height: 500px;
  overflow-y: auto;
  overflow-x: hidden;
}
.select-people /deep/ .marginLeft134 {
  margin-left: 80px;
}
.select-people /deep/ .filter-content .member-templates-condition-title {
  text-align: left;
  font-size: 14px;
  line-height: 24px;
}
.select-people /deep/ .filter-content {
  margin-top: 0;
}
.people-btn-wrap {
  width: 100%;
  background: #f2f3f4;
  box-sizing: border-box;
  padding: 0 0 24px 100px;
}
.select-people /deep/ .detail {
  margin-top: 0;
}
</style>
