index.js 14.3 KB
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 125 126 127 128 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 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
const navStyle = 'background-color: transparent;'
let navBarHeight = 38
import mallApi from '~/api/module/mall.js'
import cartApi from '~/api/module/cart.js'
// import { mineApi, shopmallApi } from '~/api/api'
// import MineApi from '~/api/mineApi/index'
// import NP from 'number-precision'
// import USERAPI from '~/api/usersApi/index'
Page({
  data: {
    navStyle,
    tabs: ['商品详情', '商品参数'],
    curTabIndex: 0,
    service: {
      1001: '不支持无理由退货',
      1002: '支持7天无理由退货',
      1003: '支持7天无理由退货(拆封后不支持)',
      1004: '支持7天无理由退货(激活后不支持)',
      1005: '支持7天无理由退货(安装后不支持)',
      1006: '支持7天无理由退货(使用后不支持)',
    },
    skuInfo: '',
    staffShop: false,
    isCarOwner: false,
    payWayActions: [{ name: '金额支付', type: 1, disabled: false }, { name: '积分兑换', type: 2, disabled: false }],
    detailInfo: {
      "id" : 267,
    "goodsSkuCode" : "2888888889071442",
    "goodsSkuName" : "系统商品009  鹅黄  28寸",
    "goodsSkuTitle" : "",
    "firstCategoryName" : "箱包",
    "secondCategoryName" : "功能箱包",
    "lastCategoryName" : "拉杆箱",
    "goodsStock" : 695,
    "salePrice" : 0.00,
    "redeemPoints" : 40,
    "sellPrice" : 150.00,
    "marketPrice" : 700.00,
    "startQty" : 1,
    "brandName" : "膳魔师",
    "returnGoodsRules" : 1001,
    "goodsCharacteristic" : "系统商品009",
    "goodsUnit" : "",
    "modelNumber" : "系统商品009",
    "productPlace" : "",
    "haveShelfLife" : 0,
    "shelfLife" : "0",
    "fragileGoods" : 0,
    "grossWeight" : 0.0000,
    "grossWeightUnit" : "kg",
    "density" : 0.0000,
    "extent" : 0,
    "width" : 0,
    "height" : 0,
    "attributeResponses" : [ {
      "attributeCode" : "1001",
      "attributeName" : "锁具类型",
      "attributeValueCode" : "2888888888892503",
      "attributeValueName" : "系统商品009"
    }, {
      "attributeCode" : "990",
      "attributeName" : "拉杆种类",
      "attributeValueCode" : "2888888888892497",
      "attributeValueName" : "系统商品009"
    }, {
      "attributeCode" : "995",
      "attributeName" : "闭合方式",
      "attributeValueCode" : "2888888888892500",
      "attributeValueName" : "系统商品009"
    }, {
      "attributeCode" : "992",
      "attributeName" : "适用场景",
      "attributeValueCode" : "2888888888892498",
      "attributeValueName" : "系统商品009"
    }, {
      "attributeCode" : "1003",
      "attributeName" : "轮子种类",
      "attributeValueCode" : "2888888888892505",
      "attributeValueName" : "系统商品009"
    }, {
      "attributeCode" : "997",
      "attributeName" : "类别",
      "attributeValueCode" : "2888888888892502",
      "attributeValueName" : "系统商品009"
    }, {
      "attributeCode" : "989",
      "attributeName" : "商品产地",
      "attributeValueCode" : "345",
      "attributeValueName" : "中国"
    }, {
      "attributeCode" : "994",
      "attributeName" : "适用性别",
      "attributeValueCode" : "349",
      "attributeValueName" : "女"
    }, {
      "attributeCode" : "1002",
      "attributeName" : "适用人群",
      "attributeValueCode" : "2888888888892504",
      "attributeValueName" : "系统商品009"
    }, {
      "attributeCode" : "991",
      "attributeName" : "是否带锁",
      "attributeValueCode" : "348",
      "attributeValueName" : "是"
    }, {
      "attributeCode" : "996",
      "attributeName" : "箱包硬度",
      "attributeValueCode" : "2888888888892501",
      "attributeValueName" : "系统商品009"
    }, {
      "attributeCode" : "987",
      "attributeName" : "商品毛重",
      "attributeValueCode" : "2888888888892496",
      "attributeValueName" : "系统商品009"
    }, {
      "attributeCode" : "993",
      "attributeName" : "材质",
      "attributeValueCode" : "2888888888892499",
      "attributeValueName" : "系统商品009"
    } ],
    "imageResponses" : [ {
      "imgUrl" : "https://img.yunzhonghe.com/image/1618215408263PefyXSUtQW.jpg",
      "imgMain" : 1,
      "imgSort" : 0
    }, {
      "imgUrl" : "https://img.yunzhonghe.com/image/1618215556741tYVyESRNzw.jpg",
      "imgMain" : 0,
      "imgSort" : 1
    } ],
    "specificationResponses" : [ {
      "specName" : "颜色",
      "specValue" : "鹅黄"
    }, {
      "specName" : "选择尺寸",
      "specValue" : "28寸"
    } ],
    "goodsDescribe" : "<p>22</p>",
    "goodsPosition" : 2,
    "saleFlag" : 1,
    "shelvesStatus" : 1001,
    "retailPrice" : null,
    "exchangeIntegralFlag" : null,
    "exchangeIntegral" : null,
    "merchantId" : null,
    "merchantName" : null
    },
    addressList: [{
      id: 1,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 1
    }, {
      id: 2,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 3,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 4,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 5,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 6,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 7,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }]
  },
  appHide() {
    wx.offAppHide()
    wx.onAppHide(() => {
      if (this.timer) clearInterval(this.timer)
      this.trackQuery.view = 5
    })
  },
  /**添加埋点结束 */
  navbarReady(e) {
    navBarHeight = e.detail.height
  },
  onPageScroll(e) {
    const { curTabIndex } = this.data
    if (curTabIndex == 0) {
      this.scrollY = e.scrollTop
    }
    this.setData({
      navStyle: e.scrollTop >= navBarHeight || curTabIndex ? '' : navStyle,
      opacity: curTabIndex == 1 ? 1 : e.scrollTop / 200,
    })
  },
  goodsActionReady(e) {
    this.setData({
      padding_bottom: e.detail
    })
  },
  goodsActionClick(e) {
    if (e.detail == 'join') return this.toAddShopCar()
    if (this.data.isCarOwner) return this.judgePayWay()
    this.showSkuModal(e.detail)
  },
  onLoad(options) {
    wx.p.router.getRouterParams(options).then(params => {
      // this.getDetail(options)
    }).catch(err => {
      console.error('参数获取失败:', err)
    })
    // this.getPlatFormAddress(staff)
  },
  showSkuModal(type) {
    // if (this.data.isCarOwner) return
    this.setData({
      showSku: true,
      clickType: type
    })
    wx.setPageStyle({
      style: {
        overflow: 'hidden'
      }
    })
  },
  // 获取默认的地址
  getPlatFormAddress(staff) {
    wx.showLoading()
    let para = {}
    if (staff) {
      para.businessType = 1
    }else{
      const SID = wx.p.util.getSessionId()
      if (!SID) return wx.hideLoading()
    }
    shopmallApi.platformAddressList(para).then(data => {
      wx.hideLoading()
      let contactAddress = '', defaultAddress = {}
      let _isSetDefault = false
      if (data && data.length) {
        data.forEach(el => {
          if (el.isDefault == 1) {
            contactAddress = el.provinceName + el.cityName + el.countyName + el.address,
              defaultAddress = el
            _isSetDefault = true
          }
        })
        if (!_isSetDefault) {
          let _first = data[0]
          contactAddress = _first.provinceName + _first.cityName + _first.countyName + _first.address,
            defaultAddress = _first
        }
      }
      this.setData({
        addressList: data,
        contactAddress,
        defaultAddress
      })
    })
  },
  jump(e) {
    let { url, isChooseAddress } = e.currentTarget.dataset
    wx.p.router.go(url, {
      isChooseAddress,
      platform: true,
      staff: this.data.staffShop,
      notIntercept: this.data.staffShop
    })
  },
  back() {
    wx.p.router.back()
  },
  changeTab(e) {
    if (this.data.opacity < 0.8) return
    this.setData({
      curTabIndex: e.currentTarget.dataset.index,
      opacity: e.currentTarget.dataset.index
    }, () => {
      setTimeout(() => {
        wx.pageScrollTo({
          scrollTop: this.scrollY
        })
      }, 200)
    })
  },
  // 获取详情
  getDetail(options) {
    if(!options || !options.id)return
    const { id, staff, score, isCarOwner, openId } = options
    const merchantId = wx.$storage.get("srcm_shopmall_merchant_id");
    this.merchantId = merchantId
    let para = { id }, canPay = true
    if (staff) para.businessType = 1
    if (isCarOwner) {
      if (openId) {
        this.shareOpenId = options.openId
      }
      this.data.enter_time = new Date().format('yyyy-MM-dd hh:mm:ss')
      this.firstEnter = true
      this.appHide()
      this.getMyIntegral()
      para.merchantId = merchantId
    }
    shopmallApi.platformGoodsDetail(para).then(res => {
      if (res && res.specificationResponses) {
        this.toGetSpecString(res, res.startQty)
      }
      if (staff) {
        canPay = score > res.redeemPoints
      }
      // if (isCarOwner) {
      //   res.retailPrice = NP.divide(res.retailPrice, 100)
      // }
      this.setData({
        detailInfo: res || {},
        canPay,
        isCarOwner
      })
    })
  },
  toGetSpecString(info, count) {
    let skuInfo = this.data, num = '', weight = ''
    num = `${count}${info.goodsUnit}`
    weight = `${info.grossWeight}${info.grossWeightUnit}`
    skuInfo = `${info.specificationResponses[0].specValue}` + `,${weight}` + `,${num}`
    this.setData({
      skuInfo
    })
  },
  getCount(e) {
    this.toGetSpecString(this.data.detailInfo, e.detail)
    this.count = e.detail
  },
  // 添加购物车
  toAddShopCar() {
    const { detailInfo, isCarOwner } = this.data
    const PARAMS = {
      goodsId: detailInfo.id,
      goodsNumber: this.count || detailInfo.startQty,
      cartType: 2,
      goodsSkuCode: detailInfo.goodsSkuCode
    }
    if (isCarOwner) {
      PARAMS.carOwnerPlatformFlag = 1
      PARAMS.merchantId = this.merchantId
      PARAMS.cartType = 4
    }
    if(isCarOwner&&!detailInfo.retailPrice&&detailInfo.exchangeIntegral)return
    cartApi.addToCart(PARAMS).then(res => {
      wx.$api.showToast('加入购物车成功')
    })
  },
  // 同步选择的地址
  resetAddress(e) {
    this.setData(e.detail)
  },
  toDuiHuang() {
    if (this.data.canPay) {
      this.showSkuModal('pay')
    }
  },
  getViewInfo() {
    wx.$api.getViewInfo(
      '.fixed_btn_wrap',
      res => {
        this.setData({
          padding_bottom: res.height
        })
      },
      this
    )
  },
  closeSku() {
    wx.setPageStyle({
      style: {
        overflow: 'unset'
      }
    })
  },
  //获取我的积分
  getMyIntegral() {
    shopmallApi.getMyIntegralApi({}).then(res => {
      if (res) {
        this.setData({
          availableIntegral: res.availableIntegral
        })
      }
    })
  },
  judgePayWay() {
    const { availableIntegral, detailInfo, payWayActions } = this.data
    if (detailInfo.exchangeIntegralFlag) {
      const canPay = +availableIntegral > +detailInfo.exchangeIntegral
      const canMoneyPay = !detailInfo.retailPrice
      if (!canPay) {
        payWayActions[1].disabled = true
        payWayActions[1].name = '积分不足'
      }
      if(canMoneyPay){
        payWayActions[0].disabled = true
      }
      this.setData({
        showPayWay: true,
        canPay,
        payWayActions
      })
    } else {
      this.jumpToPay()
    }
  },
  closePayWayModal() {
    this.setData({
      showPayWay: false
    })
  },
  //选择支付方式
  selectPayWay(e) {
    const val = e.detail
    if (val.type == 2) {
      this.useJFtoPay = true
    } else {
      this.useJFtoPay = false
    }
    this.jumpToPay()
    this.closePayWayModal()
  },
  // 跳转确认支付订单页面
  jumpToPay() {
    const { detailInfo } = this.data
    const obj = {
      useJFtoPay: this.useJFtoPay,
      merchantName: detailInfo.merchantName,
      merchantId: detailInfo.merchantId,
      goodsList: [{
        goodsImage: detailInfo.imageResponses[0].imgUrl,
        goodsSkuName: detailInfo.goodsSkuName,
        retailPrice: detailInfo.retailPrice,
        exchangeIntegral: detailInfo.exchangeIntegral,
        goodsNumber: 1,
        goodsStock: detailInfo.goodsStock,
        goodsId: detailInfo.id,
        isPay: false,
        goodsSkuCode: detailInfo.goodsSkuCode,
      }]
    }
    const query = `?goodsInfo=${JSON.stringify(obj)}`
    wx.navigateTo({
      url: '/packageShopmall/packageMall/pages/platformShop/pay/index' + query,
    });
  },
  onUnload: function () {
    const {
      isCarOwner
    } = this.data
    if (!isCarOwner) return
    if (this.timer) clearInterval(this.timer)
    this.trackQuery.view = 5
  },
  onShareAppMessage: function () {
    const merchantId = wx.$storage.get('srcm_shopmall_merchant_id')
    const userInfo = wx.p.util.getUserInfo()
    let {
      detailInfo,
      isCarOwner
    } = this.data, open_id = ''
    if (!isCarOwner) return
    this.trackQuery.view = 4
    if (userInfo) open_id = userInfo.openId
    let title = detailInfo.goodsSkuName
    let path = `${this.route}?id=${detailInfo.id}&openId=${open_id}`
    let imageUrl = ''
    detailInfo.imageResponses.map(e => {
      imageUrl = e.imgUrl
    })

    if (merchantId) path = `${path}&merchantId=${merchantId}&isCarOwner=${isCarOwner || false}`
    return {
      imageUrl,
      title,
      path
    }
  },

})