index.vue 8.63 KB
<template>
  <div class="index">
    <template v-if="$route.meta.isTab">
      <tab
        :list="tabList"
        @change="change"
        :index="tabIndex"
        :updata="updata"
        sticky
      ></tab>
      <template v-if="tabIndex==1 && showTips">
        <div class="tips flex">
          <div class="label">温馨提示:</div>
          <div class="text">
            <van-notice-bar
              scrollable
              speed="30"
              text="多次发送同张优惠券给客户,客户可领取多张,请注意控制成本"
            />
          </div>
          <div
            class="close flex"
            @click="closeTips"
          >
            <div class="sprite-icon icon-close"></div>
          </div>
        </div>
      </template>
      <template v-if="flag">
        <template v-if="list.length">
          <scroll-view
            :class="['list-box',{'tips-type':showTips && tabIndex == 1}]"
            @ReachBottom="onReachBottom"
            ref="scrollView"
          >
            <template v-for="(i,index) in list">
              <div
                :key="index"
                class="item"
              >
                <div :class="['sprite-icon', 'text-center',tabIndex == 0 ?'icon-coupon':'icon-discount', {'clear-padding':i.discountType == 3}]">
                  <template v-if="tabIndex == 0 ">
                    {{i.couponTypeName}}
                  </template>
                  <template v-else>
                    <template v-if="i.discountType == 3">
                      <span>¥</span>{{i.denomination}}
                    </template>
                    <template v-else>
                      {{discountType[i.discountType]}}
                    </template>
                  </template>
                </div>
                <div class="info">
                  <div class="top">
                    <div class="title">{{i.couponName}}</div>
                    <div class="num">剩余:{{i.remainAmount || i.residueAmount || 0}}张</div>
                    <div
                      :class="['btn', 'y-center', 'text-center', {'disabled-btn':tabIndex == 0 ?i.remainAmount<1:i.residueAmount<1}]"
                      @click="showShareModel(i)"
                    >发送</div>
                  </div>
                  <div class="bottom">
                    <template v-if="tabIndex == 0 ">
                      <div>永久有效</div>
                      <div class="right">适用于新车购买用户</div>
                    </template>
                    <template v-else>
                      <div class="right">活动商品,满足条件可使用</div>
                    </template>
                  </div>
                </div>
              </div>
            </template>
          </scroll-view>
        </template>
        <template v-else>
          <van-empty description="暂无内容" />
        </template>
      </template>
    </template>
    <template v-else>
      <router-view></router-view>
    </template>
    <template v-if="tabIndex == 1">
      <van-dialog
        v-model="showCouponModal"
        confirmButtonText="我知道了"
        confirmButtonColor="#3975C6"
        @confirm="closeCouponModal"
      >
        <div class="modal-content flex">
          <div class="sprite-icon icon-coupon-tips"></div>
          <div class="modal-content-title">温馨提示</div>
          <div class="modal-content-text">多次发送同张优惠券给客户,客户可领取多张,请注意控制成本</div>
          <div class="modal-content-radio flex">
            <van-checkbox
              v-model="modalChecked"
              checked-color="#3975C6"
              shape="square"
              icon-size="16px"
            ></van-checkbox>
            以后不再提示
          </div>
        </div>
      </van-dialog>
    </template>
  </div>
</template>

<script type='text/ecmascript-6'>
import { shareMixin, pageMixin, discountTypeMixin } from '@/mixins'
import { couponApi, boutiquecouponApi } from '@/api'
export default {
  name: 'coupon',
  mixins: [shareMixin, pageMixin, discountTypeMixin],
  data () {
    return {
      tabList: ['新车精品礼券', '商城优惠券'],
      showTips: true,
      showCouponModal: false,
      modalChecked: false,
      corpId: ''
    }
  },
  mounted () {
    let { corpId } = this.getQuery()
    if (!corpId) corpId = this.getLocalStorage('dj_scrm_corpId').corpId
    const tomorrow = this.getLocalStorage(`tips_${corpId}`)
    const couponModal = this.getLocalStorage(`modal_${corpId}`)
    this.corpId = corpId
    console.log(couponModal, tomorrow, corpId)
    if (tomorrow) this.showTips = new Date().getTime() >= tomorrow
    this.showCouponModal = !couponModal
  },
  methods: {
    getList (pageNum) {
      let { list, tabIndex } = this
      let API = tabIndex == 0 ? boutiquecouponApi : couponApi
      let target = tabIndex == 0 ? 'getBoutiqueCouponList' : 'getMerchantCouponList'
      API[target]({ pageNum }).then(res => {
        this.hideLoading()
        console.log(tabIndex == 0 ? '精品礼券' : '商城礼券', res)
        this.flag = true
        this.list = list.concat(res.list)
        this.total = res.total
      })
    },
    closeTips () {
      let { corpId } = this
      this.showTips = false
      let tomorrow = new Date(`${new Date(new Date().setDate(new Date().getDate() + 1)).format('yyyy/MM/dd')} 00:00:00`).getTime()
      this.setLocalStorage(`tips_${corpId}`, tomorrow)
    },
    closeCouponModal () {
      let { modalChecked, corpId } = this
      if (!modalChecked) return
      this.setLocalStorage(`modal_${corpId}`, true)
    }
  }
}
</script>

<style scoped lang='scss'>
.tips {
  position: sticky;
  top: 50px;
  height: 32px;
  background: #e5effd;
  z-index: 2;
  font-size: 12px;
  color: #333333;
  padding-left: 16px;
  &::before {
    content: '';
    width: 1px;
    height: 14px;
    background-color: #3975c6;
    margin-right: 7px;
  }
  .label {
    flex-shrink: 0;
  }
  .close {
    margin-left: auto;
    width: 32px;
    height: 100%;
    justify-content: flex-end;
    padding-right: 16px;
  }
  .text {
    width: calc(100% - 100px);
    .van-notice-bar {
      padding: 0;
      background: #e5effd;
      color: #333333;
      font-size: 12px;
      height: 100%;
      line-height: normal;
    }
  }
}
.list-box {
  height: calc(100vh - 100px);
  .item {
    margin-bottom: 10px;
    height: 100px;
    background: #ffffff;
    box-shadow: 0px 4px 8px 0px rgba(224, 224, 224, 0.5);
    border-radius: 4px;
    padding: 0 10px;
    box-sizing: border-box;
    display: flex;
    align-items: center;

    .sprite-icon {
      font-size: 18px;
      line-height: 25px;
      font-weight: 600;
      color: #ffffff;
      box-sizing: border-box;
      padding: 0 14px;
      flex-shrink: 0;
      text-align: center;
      span {
        font-size: 10px;
      }
    }
    .clear-padding {
      padding: 0;
    }
    .info {
      margin-left: 8px;
      flex: 1;
      .top {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        color: #2d2d2e;
        height: 58px;
        padding-top: 10px;
        position: relative;
        // border-bottom: 1px dotted #b9babb;
        &::after {
          position: absolute;
          left: 0;
          bottom: 0;
          width: 100%;
          height: 1px;
          background-image: linear-gradient(to right, transparent 0, transparent 50%, #b9babb 50%, #b9babb 100%);
          background-size: 4px 1px;
          background-repeat: repeat-x;
          content: '';
        }
        .title {
          font-weight: 600;
          font-size: 14px;
          width: 75%;
        }
        .num {
          color: #b9babb;
          margin-bottom: 4px;
          font-size: 12px;
        }
        .btn {
          width: 60px;
          box-shadow: 0px 2px 6px 2px rgba(88, 80, 255, 0.11);
          right: 0;
          font-size: 10px;
          box-sizing: border-box;
        }
        .disabled-btn {
          background: #999 !important;
        }
      }
      .bottom {
        display: flex;
        align-items: center;
        height: 31px;
        font-size: 10px;
        color: #b9babb;
        .right {
          margin-left: auto;
        }
      }
    }
  }
}
.tips-type {
  height: calc(100vh - 132px);
}
.modal-content {
  flex-direction: column;
  padding: 24px 24px 9px;
  color: rgba(10, 17, 26, 0.5);
  font-size: 15px;
  &-title {
    font-size: 17px;
    font-weight: 500;
    color: #000000;
    margin: 19px 0 8px;
  }
  &-text {
    text-align: center;
  }
  &-radio {
    margin-top: 8px;
    font-size: 14px;
    color: #666666;
    height: 16px;
    justify-content: center;
    .van-checkbox {
      margin-right: 4px;
    }
  }
}
</style>