Action.vue 8.83 KB
<template>
  <div
    :class="['action isFullSucreen flex']"
    v-if="show"
  >
    <div class="btn-box flex">
      <div
        class="item"
        @click="getPoster"
      >
        <div class="sprite-icon icon-poster"></div>
        海报
      </div>
    </div>
    <div class="price">
      <span class="unit">¥</span>{{detail.price}}<span>.{{detail.decimal}}</span>
    </div>
    <div
      :class="['btn text-center',{'disabled': iSMiniprogram || detail.activityStatus == 3 || detail.buyFlag == 2},{'short':detail.buyFlag == 3}]"
      @click="submit"
      @touchstart="touchstart"
      @touchend="touchend"
    >
      <template v-if="detail.activityStatus == 1">敬请期待</template>
      <template v-else-if="detail.activityStatus == 3">活动已结束</template>
      <template v-else>
        <template v-if="detail.buyFlag == 3">继续参团</template>
        <template v-else-if="detail.buyFlag == 2">已参团</template>
        <template v-else>立即参团</template>
      </template>
    </div>
    <pay-modal
      v-model="showModal"
      :list="formList"
      @cancel="showModal = false"
      @pay="checkOut"
      :payStatus="payStatus"
      :carInfo="carInfo"
    />
    <van-overlay
      :show="showPoster"
      @click.self="showPoster = false"
    >
      <div
        class="wrapper"
        @click.stop
      >
        <van-image
          :src="posterImg"
          width="100%"
          height="100%"
        >
          <template v-slot:loading>
            <van-loading
              type="spinner"
              size="20"
            />
          </template>
        </van-image>
      </div>
    </van-overlay>
  </div>
</template>

<script type='text/ecmascript-6'>
import { shopmallApi, wxConfig } from '@/api'
import { util } from '@/utils'
export default {
  name: 'Action',
  props: ['detail', 'updata'],
  watch: {
    'detail': function (n) {
      this.show = true
      let [price, decimal] = this.centsToyuan(n.retailPrice).toString().split('.')
      if (!decimal) decimal = '00'
      n.price = price
      n.decimal = decimal
      // limitPurchaseFlag 是否限购标志:1 否;2 是;
      //buyFlag 1是未购买或者未限购,2是已购买且达到购买上限,3是已购买且未达到购买上限
      let formList = []
      if (n.selectCarNumberFlag && n.selectCarNumberFlag == 2) formList.push({
        key: 'plateNo',
        maxlength: 10,
        name: '车牌号'
      })
      if (n.selectVehicleTypeFlag && n.selectVehicleTypeFlag == 2) {
        formList.push(...[{
          route: 'carBrands',
          name: '品牌',
          key: 'carBrandsText'
        }, {
          route: 'carSeries',
          name: '车型',
          key: 'carTypeText'
        }])
      }
      let list = [{
        key: 'formDescribeFirst',
        maxlength: 40,
        name: n.formDescribeFirst
      }, {
        key: 'formDescribeSecond',
        maxlength: 40,
        name: n.formDescribeSecond
      }, {
        key: 'formDescribeThird',
        maxlength: 40,
        name: n.formDescribeThird
      }]
      this.formList = [...formList, ...list]
    },
    updata (n) {
      this.carInfo = this.detail.carInfo
    }
  },
  data () {
    return {
      show: false,
      showModal: false,
      showPoster: false,
      formList: [],
      payStatus: Date.now(),
      posterImg: '',
      carInfo: {},
      iSMiniprogram: true
    }
  },
  mounted () {
    this.iSMiniprogram = window.__wxjs_environment === 'miniprogram'
  },
  methods: {
    submit () {
      let { detail, iSMiniprogram } = this
      if (iSMiniprogram) {
        this.showToast('参团请拨打短信中咨询热线')
        return
      }
      if (detail.buyFlag == 2 || detail.activityStatus != 2) return
      this.showModal = true
    },
    /**明天继续这里添加车型 */
    checkOut: util.debounce(({ obj, that }) => {
      let { detail } = that
      let { nickName, logo } = util.getUserInfo()
      let linkParams = util.getLocalStorage('wx_scrm_link_params') || {}
      let params = {
        ...obj,
        contactAddress: ' ',
        contactName: ' ',
        contactPhone: ' ',
        activityId: detail.id,
        orderSource: 4,
        imageUrl: logo,
        nickName,
        orderGoodsList: [{
          goodsId: detail.goodsId,
          activityPrice: detail.retailPrice * 100,
          goodsNumber: 1
        }],
        shareStaffUuid: linkParams.shareStaffUuid || '',
        shareStaffType: linkParams.shareStaffType || '',
        shareStaffPhone: linkParams.userPhone || '',
        shareStaffName: linkParams.shareStaffName || '',
        shareStaffImageUrl: linkParams.shareStaffImageUrl || ''
      }
      shopmallApi.createOrder(params).then(data => {
        that.pay(data)
      })
    }, 1e3),
    pay (orderInfo) {
      this.showLoading('结算中')
      this.payStatus = Date.now()
      shopmallApi.payOrder({
        orderCode: orderInfo.orderCode
      }).then(({ code, data, message }) => {
        this.hideLoading()
        let [url] = window.location.href.split('?')
        let redirectUrl = `${url}/success`
        if (code == '0') {
          this.showModal = false
          let { needPay, payParams } = data
          if (needPay) {
            let params = {
              nonceStr: payParams.nonceStr,
              paySign: payParams.paySign,
              signType: payParams.signType,
              timestamp: payParams.timeStamp,
              packages: payParams.packages
            }
            if (window.$ISMiniprogram) {
              wx.miniProgram.navigateTo({
                url: `/pages/h5Pay/h5Pay?payData=${encodeURIComponent(JSON.stringify({
                  nonceStr: payParams.nonceStr,
                  paySign: payParams.paySign,
                  signType: payParams.signType,
                  timeStamp: payParams.timeStamp,
                  package: payParams.packages
                }))}&redirectUrl=${redirectUrl}`
              })
            }
            else wxConfig.chooseWXPay(params).then(() => this.to('crowdfunding.success', { orderInfo }))
          } else {
            if (window.$ISMiniprogram) wx.miniProgram.navigateTo({
              url: `/pages/webView/webView?url=${encodeURIComponent(redirectUrl)}`
            })
            else this.to('crowdfunding.success', { orderInfo })
          }
        } else this.showToast(message)
      })
    },
    getPoster () {
      let { id } = this.detail
      let userInfo = this.getUserInfo()
      let { phone, nickName, logo } = userInfo
      let shareStaffType = 1
      if (this.ISWXWORK) {
        nickName = userInfo.userName
        logo = userInfo.staffAvatar
        shareStaffType = 2
        if (userInfo.loginList.length && userInfo.loginList[0].phone) phone = userInfo.loginList[0].phone
      }
      this.showLoading()
      shopmallApi.getPoster({
        id,
        nickName: this.toUnicode(nickName),
        phone,
        imageUrl: encodeURIComponent(logo),
        shareStaffType
      }).then(res => {
        console.log(res)
        this.hideLoading()
        this.posterImg = res
        this.showPoster = true
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.action {
  position: fixed;
  left: 0;
  width: calc(100% - 32px);
  height: 50px;
  background: #ffffff;
  z-index: 3;
  padding: 0 16px;
  animation: show-goods-action 0.5s forwards;
  .btn-box {
    font-size: 13px;
    font-weight: bold;
    color: #656566;
    .item {
      margin-right: 8px;
      width: 28px;
      height: 35px;
      position: relative;
      overflow: hidden;
      .mini {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        z-index: 2;
        opacity: 0;
        &-btn {
          width: 100%;
          height: 100%;
        }
      }
      .sprite-icon {
        margin: 0 auto;
      }
    }
  }
  .price {
    font-weight: 600;
    color: #f13c3d;
    font-size: 24px;
    display: flex;
    align-items: baseline;
    margin-left: 10px;
    .unit {
      font-size: 12px;
    }
    span {
      font-size: 14px;
    }
  }
  .btn {
    width: 200px;
    height: 40px;
    background: #f13c3d;
    box-shadow: 0px 2px 6px 2px rgba(241, 60, 61, 0.1);
    border-radius: 4px;
    border: 1px solid #f13c3d;
    margin-left: auto;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    box-sizing: border-box;
  }
  .disabled {
    background: #b1b1b1;
    border-color: #b1b1b1;
    box-shadow: none;
  }
  .short {
    width: 150px;
  }
}
@keyframes show-goods-action {
  0% {
    bottom: -100%;
  }
  100% {
    bottom: 0;
  }
}
.isFullSucreen {
  padding-bottom: constant(safe-area-inset-bottom) !important;
  padding-bottom: env(safe-area-inset-bottom) !important;
}
.wrapper {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 270px;
  height: 555px;
  background: #ffffff;
  box-shadow: 0px 2px 8px 0px rgba(201, 202, 204, 0.5);
  border-radius: 4px;
}
</style>