birthPopup.vue 8.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
<template>
<!-- catchtouchmove="ture" 防止触摸穿透 -->
<div v-show="isShow">
  <div class="container" v-if="!showIcon && !state">
    <div class="background" @click="showIcon = true"></div>
    <div class="info">
      <div class="info-item">
        <p style="white-space: nowrap;">
          尊敬的<span style="color: #000">
            {{ nickName }} </span
          >先生,
        </p>
        <div class="detail">
          {{
            month
          }}月是您的生日月,现在为您送上专属生日大礼包一份,祝您生日快乐!
        </div>
        <img class="tleft" :src="imgList.tleft" alt="" />
        <img class="bright" :src="imgList.bright" alt="" />
        <div class="button" @click="receive()"><span>领取生日礼包</span></div>
      </div>
    </div>
    <img class="bg" :src="imgList.background" alt="" />
    <img class="crown" :src="imgList.crown" alt="" />
    <img class="close" :src="imgList.close" @click.stop="closePopup()" alt="" />
    <img class="head" :src="avatar" alt="" />
  </div>
  <div v-else class="present" @click="iconClick()">
    <img :src="imgList.present" alt="" />
    <span>生日有礼</span>
  </div>

  <birthInfo v-if="productArr" ref="giftpackage" :giftData="productArr" @suregiftopencard="suregiftopencard"></birthInfo>
</div>
</template>

<script>
import { DFSImg } from "@/utils/index";
import birthInfo from './index.vue';
import orderDown from "@/api/order";

export default {
  name: 'birthPopup',
  created() {
    this.getBirth()
    this.getUserInfo()
  },
  deactivated() {
    this.state = true;
  },
  data() {
    return {
      showIcon: false,
      imgList: {
        // 左上角
        tleft:
          "http://mayi-newshop.oss-cn-shanghai.aliyuncs.com/public/png/b0161af3-ba7e-4792-9f19-3dc3feb4ba84.png",
        // 右下角
        bright:
          "http://mayi-newshop.oss-cn-shanghai.aliyuncs.com/public/png/aa55219c-51e6-4d3d-a4f3-4388511f1e66.png",
        // 皇冠
        crown:
          "http://mayi-newshop.oss-cn-shanghai.aliyuncs.com/public/png/970f0df4-be82-463c-b984-15650a358c15.png",
        // 背景
        background:
          "http://mayi-newshop.oss-cn-shanghai.aliyuncs.com/public/png/0976526d-0e99-4620-9847-fa54ed23b6a8.png",
        // 关闭
        close:
          "http://mayi-newshop.oss-cn-shanghai.aliyuncs.com/public/png/97d375b0-b434-4615-9048-51f4aaee5142.png",
        // 小礼物
        present:
          "http://mayi-newshop.oss-cn-shanghai.aliyuncs.com/public/png/15e91d69-dd21-4ff2-8281-510fac2fb75a.png"
      },
      state: false,
      nickName: '',
      avatar: '',
      productArr: [],
      month: '',
      isShow: false
    };
  },
  props: {
    birthGifts: {
      type: Object,
      default: {}
    },
    isShowBirth: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    birthGifts() {
      // 图片处理
      for (let i = 0; i < this.birthGifts.gifts.length; i++) {
        this.birthGifts.gifts[i].goodsSpecificationsUrl
          = DFSImg(this.birthGifts.gifts[i].goodsSpecificationsUrl)
      }
      this.productArr = this.birthGifts.gifts
      this.getBirth()
      this.getUserInfo()
    },
    isShowBirth() {
      this.isShow = this.isShowBirth
      console.log('tztzt', this.isShowBirth);
    }
  },
  methods: {
    // 领取生日礼物,跳转订单页
    receive() {
      this.$refs.giftpackage.yhjCheck = true;
    },
    // icon 点击事件
    iconClick() {
      this.state = false;
      this.showIcon = false;
    },
    // 关闭弹窗
    closePopup() {
      this.state = true;
      this.showIcon = true;
    },
    // 获取用户信息
    getUserInfo() {
侯体倬 committed
125 126 127 128
      if (this.$store.state.userInfo) {
        this.nickName = this.$store.state.userInfo.nickName
        this.avatar = this.$store.state.userInfo.avatarUrl
      } else {
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
        this.avatar = "http://mayi-newshop.oss-cn-shanghai.aliyuncs.com/public/jpg/02c0c235-daae-412d-bced-5fb315ad570e.jpg"
      }
    },
    // 对生日月份的处理
    getBirth() {
      if (this.birthGifts.gifts) {
        let birth = this.birthGifts.gifts[0].createDatetime.slice(5, 7)
        if (birth.slice(0, 1) === '0') { this.month = birth.slice(1, 2) }
        else { this.month = birth }
      }
    },
    // 领取成功回调
    suregiftopencard(val) {
      this.isShow = false
      wx.showLoading({
        title: '领取中...',
        mask: false
      })
      let orderItems = []
      for (let i = 0; i< this.birthGifts.gifts.length; i++) {
        orderItems.push({qty: 1, terminalProductGoodsId: this.birthGifts.gifts[i].grantGift, giftFlag: true})
      }
      const submitParam = {
        orderItems
      };
      if(this.$refs.giftpackage) {
        if(val) {
          submitParam.consignee = val.consignee;
          submitParam.telephone = val.mobilephone;
          submitParam.address = val.address;
          submitParam.provinceCode = val.provinceCode;
          submitParam.provinceName = val.provinceName;
          submitParam.cityCode = val.cityCode;
          submitParam.cityName = val.cityName;
          submitParam.regionCode = val.districtCode;
          submitParam.regionName = val.districtName;
          submitParam.marketingMode = 8;
          submitParam.orderType = 21;
          submitParam.marketingModeSourceId = this.birthGifts.id;
        }
      }
      orderDown.addOrderNowBuy(submitParam).then(res => {
        res = res.data
        if (res.code == 200) {
          wx.hideLoading()
          wx.showModal({
            title:'领取成功!',
            content: '请在个人中心‘我的订单’中查看详情!',
            showCancel: false
          })
        } else {
          wx.hideLoading()
          wx.showModal({
            title: '错误',
            content: `${res.msg}`,
            showCancel: false
          })
        }
      });
    }
  },
  components: {
    birthInfo
  }
};
</script>

<style lang="scss" scoped>
.background {
  position: absolute;
  top: 0;
  left: 0;
  width: 750rpx;
  height: 100vh;
  z-index: 6;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0.8;
}
.container {
  z-index: 111;
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  margin: 0 auto;
  padding: 0;
  .bg {
    position: absolute;
    left: 0;
    right: 0;
    margin: 114px auto;
    width: 263px;
    height: 349px;
    z-index: 6;
  }
  .crown {
    position: absolute;
    left: 0;
    right: 0;
    margin: 153px auto;
    width: 40px;
    height: 24px;
    z-index: 11;
  }
  .close {
    position: absolute;
    left: 0;
    right: 0;
    margin: 477px auto 72px;
    width: 32px;
    height: 32px;
    z-index: 6;
  }
  .head {
    position: absolute;
    left: 0;
    right: 0;
    margin: 172px auto 348px;
    z-index: 11;
    width: 60px;
    height: 60px;
    border-radius: 50%;
  }
  .info {
    position: absolute;
    left: 0;
    right: 0;
    margin: 287px auto;
    width: 263px;
    height: 176px;
    background: #ffffff;
    border-radius: 0px 0px 4px 4px;
    z-index: 11;

    .info-item {
      margin: 20px 123px 135px 10px;
      width: 130px;
      height: 21px;
      font-size: 15px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #a55223;
      line-height: 21px;
      .bright {
        position: absolute;
        left: 214px;
        bottom: 54px;
        width: 67px;
        height: 84px;
        z-index: 11;
      }
      .tleft {
        position: absolute;
        right: 217px;
        bottom: 305px;
        width: 71px;
        height: 81px;
        z-index: 11;
      }
      .detail {
        position: relative;
        z-index: 12;
        margin-top: 14px;
        text-align: left;
        width: 243px;
        height: 33px;
        font-size: 12px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #666666;
        line-height: 17px;
      }
      .button {
        position: absolute;
        left: 0;
        right: 0;
        margin: 32px auto;
        text-align: center;
        width: 204px;
        height: 40px;
        background: linear-gradient(135deg, #dbb292 0%, #f8dfc4 100%);
        border-radius: 21px;
        span {
          width: 90px;
          height: 21px;
          font-size: 15px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #643a23;
          line-height: 40px;
        }
      }
    }
  }
}
.present {
  position: fixed;
  top: 474px;
  right: 10px;
  img {
    display: block;
    margin: 0 auto;
    width: 49px;
    height: 49px;
    border-radius: 50%;
    margin-bottom: -5px;
  }
  span {
    width: 59px;
    height: 20px;
    background: #fd8f50;
    border-radius: 10px;
    border: 1px solid #611014;
  }
}
</style>