<!--
 * @Descripttion: 当前组件信息-即时奖励设置
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-11-21 16:37:02
 * @LastEditors: 无尘
 * @LastEditTime: 2019-12-15 14:29:47
 -->
<!--
<fraud-control></fraud-control>

import fraudControl from '@/components/active-config/configs/fraud-control.vue';
-->

<template>
  <div class="fraud-control border-box">
    <el-form
      label-width="154px"
      :model="pointFreeze"
      ref="rewardForm"
      :rules="rules"
    >
      <div
        role="alert"
        class="el-alert el-alert--info"
      >
        <i class="el-alert__icon el-icon-info font-12 color-1890ff"></i>
        <div class="el-alert__content">
          <span class="el-alert__title color-606266 font-14 font-w-400">为了获取邀请人奖励，可能会出现恶意盗刷的情况，因此系统支持对单个受邀人的成交额累计上限做控制。<br />
            这能有效的杜绝邀请人在闯关奖励、竞赛奖励中采用作弊手段（即时奖励有单独的限制控制，该成交额上限对即时奖励不起作用）。</span>
        </div>
      </div>
      <el-form-item
        label="成交额上限控制："
        prop=""
      >
        <ul class="flex ">
          <template v-for="(item, index) in modeData">
            <li
              :class="['li-cell li-second-cell flex-1 ', pointFreeze.amountLimitFlag == item.goalId ? 'li-second-active' : '']"
              :key="index + 'first'"
              @click="selectStore(item)"
            >
              <div class="li-cell-inner">
                <div class="li-cell-bottom border-box">
                  <div class="li-cell-scene">
                    <div class="li-cell-scene_title font-14 color-303133">{{ item.goalName }}</div>
                    <div class="li-cell-scene_text font-14 color-606266">{{ item.describe }}</div>
                  </div>
                </div>
              </div>
              <div class="common-cell-check">
                <div class="common-cell-triangle">
                  <div class="common-cell-outer">
                    <i class="el-icon-upload-success el-icon-check"></i>
                  </div>
                </div>
              </div>
            </li>
          </template>
        </ul>
        <div
          v-if="pointFreeze.amountLimitFlag == 1"
          class="store-select-wrap"
        >
          <div class="store-select-title">
            <span class="font-14 color-606266">限制额度：</span>
            <el-input-number
              :disabled="$route.query.editFlag || !notEdit"
              v-model="pointFreeze.amountLimitAmount"
              controls-position="right"
              :step="1"
              :step-strictly="true"
              :min="1"
              :max="9999999999"
            > </el-input-number>
            <span class="font-14 color-606266">元</span>
          </div>
        </div>
      </el-form-item>
      <div
        role="alert"
        class="el-alert el-alert--info m-t-20"
      >
        <i class="el-alert__icon el-icon-info font-12 color-1890ff"></i>
        <div class="el-alert__content">
          <span class="el-alert__title color-606266 font-14 font-w-400">转化路径的一系列节点中，消费行为尤其特殊，因为可以申请退款，所以涉及到奖励回收的问题。请根据自身的活动政策，配置相关的风险控制策略。注意：仅针对即时奖励可进行控制，闯关奖励、竞赛奖励和受邀人奖励不作回收处理。由于即时奖励中没有卡券类奖励，因此没有卡券处理方案的配置。</span>
        </div>
      </div>
      <el-form-item
        class="m-t-20"
        label="积分处理方案："
        prop=""
      >
        <ul class="flex  ">
          <template v-for="(item, index) in contentData">
            <li
              :class="['li-cell li-second-cell flex-1 ', pointFreeze.pointProgram == item.goalId ? 'li-second-active' : '']"
              :key="index + 'first'"
              @click="selectMoney(item)"
            >
              <div class="li-cell-inner">
                <div class="li-cell-bottom border-box">
                  <div class="li-cell-scene">
                    <div class="li-cell-scene_title font-14 color-303133">{{ item.goalName }}</div>
                    <div class="li-cell-scene_text font-14 color-606266">{{ item.describe }}</div>
                  </div>
                </div>
              </div>
              <div class="common-cell-check">
                <div class="common-cell-triangle">
                  <div class="common-cell-outer">
                    <i class="el-icon-upload-success el-icon-check"></i>
                  </div>
                </div>
              </div>
            </li>
          </template>
        </ul>
        <div
          v-if="pointFreeze.pointProgram == 1"
          class="store-select-wrap child-select-wrap"
        >
          <div class="store-select-title">
            <span class="font-14 color-606266">延时时长：</span>
            <el-input-number
              :disabled="$route.query.editFlag"
              v-model="pointFreeze.pointControlDay"
              controls-position="right"
              :step="1"
              :step-strictly="true"
              :min="1"
              :max="99"
            > </el-input-number>
            <span class="font-14 color-606266 p-l-3 p-r-10">天</span>
          </div>
        </div>
        <div
          v-if="pointFreeze.pointProgram == 2"
          class="store-select-wrap child-select-wrap"
        >
          <div class="store-select-title">
            <span class="font-14 color-606266">冻结时长：</span>
            <el-input-number
              :disabled="$route.query.editFlag"
              v-model="pointFreeze.pointControlDay"
              controls-position="right"
              :step="1"
              :step-strictly="true"
              :min="1"
              :max="99"
            > </el-input-number>
            <span class="font-14 color-606266 p-l-3 p-r-10">天</span>
          </div>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import showMsg from '@/common/js/showmsg';
export default {
  name: 'fraud-control',
  props: {
    value: {
      type: [Object, Array],
      default() {
        return {
          amountLimitFlag: 0,
          amountLimitAmount: 1,
          pointProgram: 1, //0、不限制，1、延时发放（推荐），2积分冻结
          pointControlDay: 1, //限制延时
          "stepType": 1 //步骤类型 类型：1服务号关注，2活动营销页访问奖励，3会员认证奖励，4游戏参与奖励，5卡券领取奖励6，消费奖励
        };
      }
    },
    notEdit: {
      type: Boolean,
      default: true
    }
  },
  components: {},
  data() {
    return {
      pointFreeze: {
        amountLimitFlag: 0,
        amountLimitAmount: 1,
        pointProgram: 1, //0、不限制，1、延时发放（推荐），2积分冻结
        pointControlDay: 1, //限制延时
        stepType: 1 //步骤类型 类型：1服务号关注，2活动营销页访问奖励，3会员认证奖励，4游戏参与奖励，5卡券领取奖励6，消费奖励
      },
      modeData: [
        {
          goalId: 0,
          goalName: '不控制上限 (推荐)',
          describe: '同一个受邀人无论消费多少，都会计入累计成交额。'
        },
        {
          goalId: 1,
          goalName: '控制成交额上限',
          describe: '限制针对单个受邀人统计的成交额，超过该额度之后，溢出的成交额不计入奖励结算的统计。'
        }
      ],
      contentData: [
        {
          goalId: 1,
          goalName: '延时发放（推荐）',
          describe: '根据自身的退换货有效期政策，设置延时发放积分的时长，积分发放后再退款，系统不会追扣积分。'
        },
        {
          goalId: 2,
          goalName: '积分冻结',
          describe: '积分发放没有延时，但受邀人退款后会追扣（回收）积分，可设置积分冻结期来确保退换服务期内的积分安全。注意：闯关奖励、竞赛奖励、受邀人奖励不会追扣(回收)。'
        },
        {
          goalId: 0,
          goalName: '不予控制',
          describe: '积分发放没有延时，也不会对受邀人的 退款事件作积分的追扣（回收）。'
        }
      ]
    };
  },
  methods: {
    /**
     * 表单提交
     */
    submitForm() {
      const that = this;
      return new Promise(function(resolve, reject) {
        that.$refs['rewardForm'].validate(valid => {
          if (valid) {
            that.$emit('input', that.pointFreeze);
            if (that.pointFreeze.amountLimitFlag ==1 && !that.pointFreeze.amountLimitAmount) {
              resolve(false);
            }
            if (that.pointFreeze.pointProgram ==1 && !that.pointFreeze.pointControlDay) {
              resolve(false);
            }
            if (that.pointFreeze.pointProgram ==2 && !that.pointFreeze.pointControlDay) {
              resolve(false);
            }
            resolve(that.pointFreeze);
          } else {
            resolve(false);
          }
        });
      });
    },
    /**
     * 选择控制：
     */
    selectStore(item) {
      const that = this;
      if (that.$route.query.hasOwnProperty('activityId') && !that.notEdit) {
        showMsg.showmsg('成交额上限控制禁止修改', 'warning');
        return false;
      }
      if (that.$route.query.hasOwnProperty('editFlag')) {
        return false;
      }
      that.pointFreeze.amountLimitFlag = item.goalId;
    },
    /**
     * 选择积分处理方案：
     */
    selectMoney(item) {
      const that = this;
      if (that.$route.query.hasOwnProperty('editFlag')) {
        return false;
      }
      that.pointFreeze.pointProgram = item.goalId;
    },
  },
  watch: {
    value(newData) {
      const that = this;
      that.pointFreeze = JSON.parse(JSON.stringify(newData));
    }
  },
  mounted() {
    const that = this;
    that.pointFreeze = JSON.parse(JSON.stringify(that.value));
  }
};
</script>
<style lang="less" scoped>
.p-l-3 {
  padding-left: 3px;
}
.p-l-10 {
  padding-left: 10px;
}
.p-r-10 {
  padding-right: 10px;
}
.m-l-10 {
  margin-left: 10px;
}
.m-l-16 {
  margin-left: 16px;
}
.fraud-control {
  width: 100%;
  padding: 20px;
  background: #fff;
  .fraud-control-title {
    margin: 0 auto;
    text-align: center;
    font-weight: 600;
    line-height: 30px;
    padding-top: 27px;
    margin-bottom: 48px;
  }
  .m-b-0 {
    margin-bottom: 0;
  }
  .m-t-48 {
    margin-top: 48px;
  }
  .m-t-50 {
    margin-top: 50px;
  }
  .fraud-control-subtitle {
    width: 800px;
    margin: 14px auto;
    line-height: 20px;
    font-weight: 500;
    text-align: center;
  }
  .el-alert--info {
    width: 799px;
    margin-bottom: 17px;
    background: #e6f7ff;
    border: 1px solid #91d5ff;
    .el-alert__icon {
      padding-top: 5px;
      align-self: flex-start;
    }
    .el-alert__content {
      line-height: 22px;
      padding-right: 0;
    }
  }
  ul {
    .li-cell {
      position: relative;
      width: 427px;
      // height: 131px;
      background: rgba(255, 255, 255, 1);
      border-radius: 4px;
      border: 1px solid rgba(220, 223, 230, 1);
      margin-left: 10px;
      cursor: pointer;
      max-width: 30%;
      transition: all 0.3s;
      &:hover {
        -webkit-transform: translateY(-10px);
        -moz-transform: translateY(-10px);
        -o-transform: translateY(-10px);
        transform: translateY(-10px);
        box-shadow: 0px 2px 10px 0 rgba(174, 181, 189, 0.5);
      }
      &:first-child {
        margin-left: 0;
      }
      .li-cell-inner {
        border-radius: 4px;
        width: 100%;
        height: 100%;
        .li-cell-left {
          height: 100%;
          padding-left: 30px;
          img {
            max-width: 66px;
            max-height: 66px;
          }
        }
        .li-cell-right {
          height: 100%;
          padding: 16px 36px;
          .li-cell-active_name {
            font-weight: 600;
            line-height: 25px;
          }
          .li-cell-active_describe {
            margin-top: 13px;
            font-weight: 500;
            line-height: 20px;
          }
        }
      }
      .common-cell-check {
        display: none;
        position: absolute;
        right: 0;
        bottom: 0;
        width: 22px;
        height: 22px;
        z-index: 1;
        .common-cell-triangle {
          position: relative;
          width: 100%;
          height: 100%;
          overflow: hidden;
          .common-cell-outer {
            position: absolute;
            right: -16px;
            bottom: -6px;
            width: 32px;
            height: 20px;
            background: #1890ff;
            text-align: center;
            -webkit-transform: rotate(-45deg);
            -moz-transform: rotate(-45deg);
            transform: rotate(-45deg);

            i {
              position: absolute;
              top: 0px;
              left: 7px;
              font-size: 12px;
              color: #fff;
              -webkit-transform: rotate(45deg);
              -moz-transform: rotate(45deg);
              transform: rotate(45deg);
            }
          }
        }
      }
      /* 二级 */
      &.li-second-cell {
        max-width: 234px;
        // height: 141px;
        padding: 20px;
        .li-cell-inner {
          .li-cell-bottom {
            // height: 60px;
            background: #fff;
            border-radius: 0 0 4px 4px;
            .li-cell-scene {
              .li-cell-scene_title {
                font-weight: 600;
                line-height: 20px;
              }
              .li-cell-scene_text {
                margin-top: 10px;
                font-weight: 500;
                line-height: 20px;
                /* text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 3; //规定几行显示省略号
                -webkit-box-orient: vertical;
                overflow: hidden; */
              }
            }
          }
        }
        .common-cell-check {
          .common-cell-triangle {
            .common-cell-outer {
              background: #1890ff;
              i {
                color: #fff;
              }
            }
          }
        }
      }
      &.li-second-active {
        border-radius: 4px;
        border: 2px solid rgba(24, 144, 255, 1);
        box-shadow: 0px 6px 8px 0px rgba(166, 181, 199, 0.34);
        .common-cell-check {
          display: block;
          .common-cell-triangle {
            border-bottom-right-radius: 1px;
          }
        }
      }
    }
  }
  .store-select-wrap {
    width: 580px;
    // height: 470px;
    margin-top: 10px;
    padding: 20px;
    background: rgba(245, 247, 250, 1);
    &.w-845 {
      width: 845px;
    }
    .add-line {
      height: 50px;
      line-height: 50px;
      background: #fff;
    }
    .el-input-number {
      width: 123px;
    }
    .store-select-body {
      margin-top: 20px;
    }
    &.child-select-wrap {
      padding-left: 20px;
      .el-input-number {
        width: 123px;
      }
    }
  }
}
</style>
