groupGoodsDetail.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. const app = getApp()
  2. const api = require('../../../../../request/api');
  3. const http = require('../../../../../request/http');
  4. const utils = require('../../../../../utils/util.js');
  5. const storeKeys = require('../../../../../utils/storageKeys.js');
  6. Page({
  7. data: {
  8. isLogOn: false, //是否已登录
  9. userInfo: {},
  10. goodsId: "", //商品id
  11. activity_id: "",//活动id
  12. isLoading: true, //是否处于加载
  13. isShare: false, //是否来源分享
  14. statusBarHeight: app.globalData.statusBarHeight,
  15. isIphoneX: app.globalData.isIphoneX,
  16. details: {}, //商品线详情数据
  17. groupbuy: {},//拼团数据
  18. richHtml: "", //富文本内容
  19. defaultSpecIndex: 0, //默认选中的规格
  20. selectSpec: {}, //选中的规格
  21. selectSku: {}, //选中的规格对应信息
  22. currentSwiper: 0, //轮播索引
  23. isRemoved: false, //是否已下架
  24. isOverdue: false, //是否不存在、过期
  25. couponNumber: 1,
  26. isShowNavMenu: false, //是否显示导航栏菜单
  27. isShowNavTab: false, //是否显示导航tab栏
  28. currentNavTab: 0, //导航栏tab切换索引
  29. richTextTop: 0, //商品详情区域到顶部的距离
  30. swiperData: [{}, {}, {}],
  31. showSharePopup: false, //是否显示分享菜单Popup
  32. showParameterPopup: false, //是否显示参数说明Popup
  33. showBuyPopup: false, //是否显示购买选择Popup
  34. showCouponPopup: false, //是否显示领优惠券Popup
  35. couponList: [], //可用优惠券列表
  36. buyNumber: 1, //购买数量
  37. cartTotal: 0, //购物车总数
  38. canvasPosterUrl: "", //海报地址
  39. showPoster: false, //是否现在绘制vf好的海报
  40. isOnLoad: true,
  41. appraiseList: [], //评价列表
  42. appraiseTotal: 0, //评价总数
  43. addressId: "", //用户地址id
  44. expressPrice: 0, //运费
  45. isActivity:false, //是否存在活动
  46. timer: null , //活动倒计时定时器
  47. actTimes: 0, //活动到期时间
  48. countDownDay: '0',
  49. countDownHour: '0',
  50. countDownMinute: '0',
  51. countDownSecond: '0',
  52. groupList: [],//拼团列表
  53. allgroupList:[],//全部拼团列表
  54. showGroupList:false,//是否显示全部拼团
  55. isClose:false,//活动结束
  56. isjoin:false,//是否参与拼团
  57. joinid:"",
  58. isfission:false,//是否裂变拼团
  59. },
  60. goIndex: function (e){
  61. wx.switchTab({
  62. url: '/pages/tabBar/index/index'
  63. })
  64. },
  65. onShowGroupList: function () {
  66. this.setData({
  67. showGroupList: true,
  68. })
  69. },
  70. onCloseGroupList: function (e) {
  71. this.setData({
  72. showGroupList: false,
  73. })
  74. },
  75. onLoad: function (options) {
  76. console.log("页面 JS")
  77. console.log(options)
  78. if (options) {
  79. //商品id
  80. let activity_id = options.activity_id || options.publicId || "5";
  81. this.setData({
  82. activity_id
  83. })
  84. this.setData({
  85. isShare: options.share ? true : false,
  86. isfission:options.isfission == 1 ? true : false,
  87. })
  88. //分享人id 107295
  89. let shareId = options.shareId || "";
  90. console.log("分享人id"+shareId)
  91. shareId && utils.setStorageSync(storeKeys.SHAREID, shareId);
  92. }
  93. // if (!utils.getStorageSync(storeKeys.TOKEN)) {
  94. // wx.navigateTo({
  95. // url: "/pages/tabBar/login/login"
  96. // })
  97. // return;
  98. // }
  99. this.promotion();
  100. // this.getFreight()
  101. this.getGoodsDetails(true)
  102. this.changeCountRecord();
  103. },
  104. // 数据统计埋点
  105. changeCountRecord(){
  106. // 裂变活动不统计
  107. let visit_type = 1
  108. if(this.data.isfission){
  109. visit_type = 10
  110. }
  111. app.countRecord()
  112. app.countRecordActivity(visit_type, this.data.activity_id)
  113. },
  114. onShow: function (options) {
  115. console.log("onshow触发")
  116. if (!this.data.isOnLoad) {
  117. this.getGoodsDetails();
  118. }
  119. this.getAppraiseList();
  120. this.data.isOnLoad = false;
  121. if (!utils.getStorageSync(storeKeys.TOKEN)) {
  122. this.setData({
  123. isLogOn: false
  124. })
  125. } else {
  126. let userInfo = utils.getStorageSync(storeKeys.USERINFO) || {};
  127. this.setData({
  128. isLogOn: true,
  129. userInfo
  130. })
  131. }
  132. },
  133. onUnload() {
  134. this.clearTime();
  135. },
  136. onHide() {
  137. this.clearTime();
  138. },
  139. //获取评价列表
  140. getAppraiseList() {
  141. console.log("商品id")
  142. console.log(this.data.goodsId)
  143. http.request({
  144. url: api.URL + '/api/Comment/listRows?goodsId=' + this.data.goodsId + '&limit=2',
  145. method: 'GET',
  146. noToast: true,
  147. token: utils.getStorageSync(storeKeys.TOKEN),
  148. success: (res) => {
  149. let data = res.data.data;
  150. this.setData({
  151. appraiseList: data.list || [],
  152. appraiseTotal: data.total
  153. })
  154. },
  155. error: (res) => {},
  156. })
  157. },
  158. //获取运费
  159. getFreight() {
  160. let goodsId = this.data.goodsId;
  161. let goodsSkuId = this.data.selectSku.goods_sku_id || 0;
  162. let goodsNum = this.data.buyNumber || 1;
  163. http.request({
  164. url: api.URL + '/api/goods/calc_delivery_amount&goodsId=' + goodsId + '&goodsSkuId=' + goodsSkuId + '&goodsNum=' + goodsNum,
  165. method: 'GET',
  166. noToast: true,
  167. token: utils.getStorageSync(storeKeys.TOKEN),
  168. success: (res) => {
  169. console.log(res)
  170. let expressPrice = res.data.data.expressPrice
  171. this.setData({
  172. expressPrice
  173. })
  174. },
  175. error: (res) => {},
  176. })
  177. },
  178. // 获取商品详情
  179. getGoodsDetails(state) {
  180. //用户地址id
  181. let addressId = this.data.addressId || "";
  182. if (state || addressId) {
  183. wx.showLoading({
  184. title: "加载中"
  185. });
  186. }
  187. let staffUserId = utils.getStorageSync(storeKeys.SHAREID) || utils.getStorageSync(storeKeys.APPLESID) || "";
  188. let apiurl = this.data.isfission?'/api/groupbuylb.Activity/detail?activity_id=':'/api/groupbuy.Activity/detail?activity_id=';
  189. http.request({
  190. url: api.URL + apiurl + this.data.activity_id,
  191. method: 'GET',
  192. noToast: true,
  193. token: utils.getStorageSync(storeKeys.TOKEN),
  194. success: (res) => {
  195. console.log(res)
  196. if (state || addressId) {
  197. wx.hideLoading();
  198. }
  199. this.data.addressId = "";
  200. let details = res.data.data.data.goods;
  201. console.log(details);
  202. // 10普通商品 20赠品 30套餐
  203. if(details.goods_type == 20){
  204. details.full_send_act = null;
  205. details.is_send_act = 0
  206. details.mj_send_act = null
  207. }
  208. if(details.full_send_act){ // 满就送
  209. // 当所有的赠品库存都是0:true
  210. if(details.full_send_act.empty_gifts){
  211. details.full_send_act = null;
  212. }
  213. }
  214. // status => 商品状态(10上架 20下架)
  215. let isRemoved = details.status == 20 ? true : false;
  216. //处理富文本
  217. let content = details.content;
  218. content = content.replace(/<p><br\/><\/p>/g, "");
  219. let richHtml = content.replace(/<p><img/gi, '<p style="padding: 0px !important; line-height: 0px !important;"><img');
  220. richHtml = richHtml.replace(/<p>/gi, '<p style="padding: 0px 0 0 0; line-height: 24px">');
  221. richHtml = richHtml.replace(/<img/gi, '<img style="width:100%!important; height: auto !important;display: flex !important"');
  222. // 默认选中商品规格
  223. let specList = details.specList[0] || [];
  224. let newIndex = -1;
  225. let buyNumber = this.data.buyNumber || 1;
  226. //计算库存是否不足
  227. if (specList && specList.valueList) {
  228. for (let i = 0; i < specList.valueList.length; i++) {
  229. let item = specList.valueList[i];
  230. for (let x = 0; x < details.skuList.length; x++) {
  231. if (parseInt(item.spec_value_id) == parseInt(details.skuList[x].goods_sku_id)) {
  232. if (details.skuList[x].stock_num < 1 || !details.skuList[x].stock_num) {
  233. item.lack = true;
  234. } else {
  235. if (newIndex == -1) {
  236. if (details.skuList[x].stock_num < buyNumber) {
  237. buyNumber = details.skuList[x].stock_num
  238. }
  239. newIndex = i;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. }
  246. //单规格
  247. if (details.spec_type == 10) {
  248. buyNumber = 1
  249. }
  250. this.data.defaultSpecIndex = newIndex;
  251. let selectSpec = specList.valueList && specList.valueList[this.data.defaultSpecIndex] || {};
  252. let groupbuy = res.data.data.data.groupbuy;
  253. let isActivity =false;
  254. if(groupbuy){
  255. this.clearTime();
  256. this.data.actTimes = groupbuy.fmt_end_time;
  257. // this.data.groupbuy = groupbuy;
  258. let isjoin = false;
  259. if(groupbuy.help){
  260. isjoin = true;
  261. this.data.joinid = groupbuy.help.join_id;
  262. }
  263. let groupList = groupbuy.to_pt_list.length>2?groupbuy.to_pt_list.slice(0,2):groupbuy.to_pt_list;
  264. let allgroupList = groupbuy.to_pt_list;
  265. allgroupList.forEach(element => {
  266. if(element.nick_name.length>4){
  267. element.t_nick_name = element.nick_name.substr(0,4)+"..."
  268. }else{
  269. element.t_nick_name = element.nick_name
  270. }
  271. });
  272. this.setData({
  273. groupbuy,
  274. isjoin,
  275. groupList,
  276. allgroupList
  277. })
  278. this.changeTimeText();
  279. this.newCountdown()
  280. isActivity = true;
  281. }
  282. this.setData({
  283. isLoading: false,
  284. details,
  285. richHtml,
  286. selectSpec,
  287. buyNumber,
  288. isActivity,
  289. isRemoved,
  290. goodsId:details.goods_id
  291. })
  292. setTimeout(() => {
  293. this.data.richTextTop <= 0 && this.getRichTextTop();
  294. this.getFreight();
  295. this.getAppraiseList();
  296. state && this.getCanvasImageInfo();
  297. }, 100)
  298. },
  299. error: (res) => {
  300. if (res.data.status == 500) {
  301. this.setData({
  302. isClose: true
  303. })
  304. }
  305. },
  306. })
  307. },
  308. //活动倒计时
  309. newCountdown(){
  310. if(!this.data.actTimes){
  311. this.setData({
  312. isActivity:false
  313. })
  314. return;
  315. }
  316. this.data.timer = setInterval(()=> {
  317. let actTimes = this.data.actTimes;
  318. if (actTimes > 0) {
  319. this.changeTimeText();
  320. } else {
  321. this.setData({
  322. isClose: true
  323. })
  324. this.clearTime();
  325. this.getGoodsDetails();
  326. }
  327. actTimes--;
  328. this.data.actTimes = actTimes;
  329. }, 1000);
  330. },
  331. //倒计时时间文字变化
  332. changeTimeText(){
  333. let actTimes = this.data.actTimes;
  334. if(!actTimes){
  335. return;
  336. }
  337. this.setData({
  338. countDownDay: utils.newDateForma(actTimes, "day"),
  339. countDownHour: utils.newDateForma(actTimes, "hours"),
  340. countDownMinute: utils.newDateForma(actTimes, "minutes"),
  341. countDownSecond: utils.newDateForma(actTimes, "seconds"),
  342. });
  343. },
  344. //清除倒计时
  345. clearTime() {
  346. clearTimeout(this.data.timer);
  347. this.data.timer = null;
  348. },
  349. //生成分享图
  350. getCanvasImageInfo() {
  351. let canvasImage = this.data.details.goods_image_text + "?x-oss-process=image/resize,w_400/format,png";
  352. let canvasBack = `${api.URL}/uploads/image/image_share_goods.png`;
  353. //背景图
  354. let promise1 = new Promise(function (resolve) {
  355. wx.getImageInfo({
  356. src: canvasBack,
  357. success: function (res) {
  358. resolve(res)
  359. },
  360. fail: function (res) {
  361. wx.hideLoading();
  362. }
  363. })
  364. })
  365. //商品图
  366. let promise2 = new Promise(function (resolve) {
  367. wx.getImageInfo({
  368. src: canvasImage,
  369. success: function (res) {
  370. resolve(res)
  371. },
  372. fail: function (res) {
  373. wx.hideLoading();
  374. }
  375. })
  376. })
  377. Promise.all([promise1, promise2]).then((values) => {
  378. this.canvasImgMin(values[0], values[1]);
  379. }).catch((error) => {})
  380. },
  381. //执行绘制海报
  382. canvasImgMin(canvasBack, canvasImage) {
  383. let canvasWidth = wx.getSystemInfoSync().windowWidth;
  384. let Rpx = (canvasWidth / 660).toFixed(2);
  385. let ctx = wx.createCanvasContext('posterCanvas');
  386. ctx.clearRect(Rpx * 0, 0, 330, 264);
  387. ctx.setFillStyle('#FFFFFF');
  388. ctx.fillRect(Rpx * 0, 0, 330, 264);
  389. //绘制封面
  390. let canvasW = 174;
  391. let canvasH = 174;
  392. let cData = utils.getSXYWH(canvasW, canvasH, canvasImage.width, canvasImage.height);
  393. ctx.drawImage(canvasImage.path, cData.sX, cData.sY, cData.sW, cData.sH, 16, 74, canvasW, canvasH);
  394. //绘制背景
  395. ctx.drawImage(canvasBack.path, 0, 0, 330, 264);
  396. //¥
  397. ctx.setFillStyle('#F2F2F2');
  398. ctx.font = `normal 400 ${(14).toFixed(0)}px PingFang-SC-Medium`
  399. let priceTag = "¥";
  400. let price = this.data.groupbuy.group_price || "0.00";
  401. let priceB = 1;
  402. if (price.length == 5) {
  403. priceB = 2;
  404. }
  405. if (price.length == 6) {
  406. priceB = 3;
  407. }
  408. if (price.length == 7) {
  409. priceB = 4;
  410. }
  411. if (price.length >= 8) {
  412. priceB = 5;
  413. }
  414. ctx.fillText(priceTag, 232 - (priceB * 7), 182);
  415. //价格
  416. ctx.font = `normal bold ${(26).toFixed(0)}px PingFang-SC-Medium`
  417. ctx.fillText(price, 242 - (priceB * 7), 182);
  418. ctx.draw(true);
  419. setTimeout(() => {
  420. this.getCanvasUrl()
  421. }, 800)
  422. },
  423. //获取画布图片地址
  424. getCanvasUrl() {
  425. let _this = this;
  426. wx.canvasToTempFilePath({
  427. fileType: 'jpg',
  428. canvasId: 'posterCanvas',
  429. success: (res) => {
  430. if (res.tempFilePath) {
  431. console.log(res)
  432. wx.hideLoading();
  433. _this.setData({
  434. canvasPosterUrl: res.tempFilePath
  435. })
  436. // wx.showShareImageMenu({
  437. // path: res.tempFilePath
  438. // })
  439. }
  440. },
  441. fail(res) {}
  442. }, this);
  443. },
  444. //监听页面滚动
  445. onPageScroll(e) {
  446. if (e.scrollTop < (this.data.richTextTop - this.data.statusBarHeight - 30) && this.data.isShowNavTab) {
  447. this.setData({
  448. isShowNavTab: false,
  449. currentNavTab: 0
  450. })
  451. } else if (e.scrollTop >= (this.data.richTextTop - this.data.statusBarHeight - 30) && !this.data.isShowNavTab) {
  452. this.setData({
  453. isShowNavTab: true,
  454. currentNavTab: 1
  455. })
  456. }
  457. },
  458. //获取详情区域到头部的距离
  459. getRichTextTop() {
  460. wx.createSelectorQuery().select('#richTextContainer').boundingClientRect((rect) => {
  461. if (rect) {
  462. this.data.richTextTop = rect.top || 0;
  463. }
  464. }).exec()
  465. },
  466. //监听轮播图滚动
  467. swiperChange(e) {
  468. this.setData({
  469. currentSwiper: e.detail.current
  470. })
  471. },
  472. //显示导航栏菜单
  473. showNavMenu() {
  474. this.setData({
  475. isShowNavMenu: true
  476. })
  477. },
  478. //隐藏导航栏菜单
  479. hideNavMenu() {
  480. this.setData({
  481. isShowNavMenu: false
  482. })
  483. },
  484. //导航栏切换tab
  485. changeNavTab(e) {
  486. let {
  487. index
  488. } = e.currentTarget.dataset;
  489. let scrollTop = index == 0 ? 0 : (this.data.richTextTop - this.data.statusBarHeight - 30);
  490. wx.pageScrollTo({
  491. scrollTop: scrollTop,
  492. duration: 300
  493. })
  494. this.setData({
  495. currentNavTab: index
  496. })
  497. },
  498. //前往海报绘制
  499. goToPoster() {
  500. if (!utils.getStorageSync(storeKeys.TOKEN)) {
  501. wx.navigateTo({
  502. url: "/pages/tabBar/login/login"
  503. })
  504. return;
  505. }
  506. let {
  507. goods_image_text,
  508. goods_name,
  509. spec_type,
  510. goods_price_min,
  511. shopping_discount_amount
  512. } = this.data.details;
  513. let goods_price = goods_price_min;
  514. let newPrice = "";
  515. if(shopping_discount_amount && shopping_discount_amount>0){
  516. newPrice = (parseFloat(((parseFloat(goods_price)*100) - (parseFloat(shopping_discount_amount)*100)) /100).toFixed(2)).toString();
  517. }
  518. let goodData = {
  519. goods_image: goods_image_text,
  520. goods_name,
  521. goods_price,
  522. newPrice,
  523. goodsId: this.data.goodsId
  524. }
  525. let url = "/pages/cart/pages/goodsPoster/goodsPoster?goodData=" + JSON.stringify(goodData);
  526. this.hideSharePopup();
  527. app.navigateToUrl(url)
  528. },
  529. //底部显示分享菜单
  530. showSharePopup() {
  531. if (this.data.isOverdue) {
  532. utils.toast("商品过期或不存在")
  533. return;
  534. }
  535. this.setData({
  536. showSharePopup: true
  537. })
  538. },
  539. //底部隐藏分享菜单
  540. hideSharePopup() {
  541. this.setData({
  542. showSharePopup: false
  543. })
  544. },
  545. //底部显示参数说明
  546. showParameterPopup() {
  547. this.setData({
  548. showParameterPopup: true
  549. })
  550. },
  551. //底部隐藏参数说明
  552. hideParameterPopup() {
  553. this.setData({
  554. showParameterPopup: false
  555. })
  556. },
  557. // 回到首页
  558. goHome() {
  559. wx.switchTab({
  560. url: '/pages/tabBar/index/index'
  561. })
  562. },
  563. //查看轮播图片
  564. swiperPreview(e) {
  565. let src = e.currentTarget.dataset.src;
  566. let list = [];
  567. this.data.details.goods_images.forEach((item) => {
  568. list.push(item.preview_url);
  569. })
  570. this.previewImage(src, list);
  571. },
  572. // 图片预览
  573. previewImage(current, urls) {
  574. wx.previewImage({
  575. current: current,
  576. urls: urls
  577. })
  578. },
  579. pageBack() {
  580. let pages = getCurrentPages();
  581. if(pages.length<=1){
  582. this.goHome();
  583. } else{
  584. wx.navigateBack();
  585. }
  586. },
  587. navigateTo(e) {
  588. app.navigateTo(e);
  589. },
  590. navigateToToken(e) {
  591. if (!utils.getStorageSync(storeKeys.TOKEN)) {
  592. wx.navigateTo({
  593. url: "/pages/tabBar/login/login"
  594. })
  595. return;
  596. }
  597. app.navigateTo(e);
  598. },
  599. onShareAppMessage: function (e) {
  600. if (this.data.isOverdue) {
  601. return {
  602. title: app.globalData.shareTitle,
  603. imageUrl: app.globalData.shareImage,
  604. path: app.globalData.sharePath,
  605. }
  606. }
  607. let {
  608. goods_image_text,
  609. goods_name
  610. } = this.data.details;
  611. let path = "pages/activity/pages/groupShopping/groupGoodsDetail/groupGoodsDetail?activity_id=" + this.data.activity_id + "&share=xcx";
  612. let userId = this.data.userInfo.user_id || '';
  613. this.hideSharePopup();
  614. if (userId) {
  615. path = "pages/activity/pages/groupShopping/groupGoodsDetail/groupGoodsDetail?activity_id=" + this.data.activity_id + "&shareId=" + userId + "&share=xcx";
  616. }
  617. if(this.data.isfission){
  618. path = path+'&isfission=1'
  619. }
  620. console.log(this.data.canvasPosterUrl)
  621. return {
  622. title: goods_name,
  623. imageUrl: this.data.canvasPosterUrl || goods_image_text,
  624. path: path
  625. }
  626. },
  627. onShareTimeline: function () {
  628. if (this.data.isOverdue) {
  629. return {
  630. title: app.globalData.shareTitle,
  631. imageUrl: app.globalData.shareImage,
  632. path: app.globalData.sharePath,
  633. }
  634. }
  635. let {
  636. goods_image_text,
  637. goods_name
  638. } = this.data.details;
  639. let path = "pages/activity/pages/groupShopping/groupGoodsDetail/groupGoodsDetail?activity_id=" + this.data.activity_id + "&share=xcx";
  640. let userId = this.data.userInfo.user_id || '';
  641. if (userId) {
  642. path = "pages/activity/pages/groupShopping/groupGoodsDetail/groupGoodsDetail?activity_id=" + this.data.activity_id + "&shareId=" + userId + "&share=xcx";
  643. }
  644. if(this.data.isfission){
  645. path = path+'&isfission=1'
  646. }
  647. this.hideSharePopup();
  648. return {
  649. title: goods_name,
  650. imageUrl: goods_image_text,
  651. path: path
  652. }
  653. },
  654. // 普通用户切换绑定关系
  655. promotion() {
  656. let sharerId = utils.getStorageSync(storeKeys.SHAREID) || utils.getStorageSync(storeKeys.APPLESID) || "";
  657. console.log("sharerId", sharerId)
  658. if (!sharerId) {
  659. return;
  660. }
  661. let data = {
  662. sharerId: sharerId,
  663. isScanCode: "1"
  664. }
  665. http.request({
  666. url: api.URL + '/api/promotion/ch_upper',
  667. data: data,
  668. method: 'POST',
  669. token: utils.getStorageSync(storeKeys.TOKEN),
  670. noLogin: true,
  671. noToast: true,
  672. success: function (res) {
  673. console.log("success")
  674. console.log(res)
  675. },
  676. error: function (res) {
  677. console.log("error")
  678. console.log(res)
  679. }
  680. })
  681. },
  682. //商品详情
  683. goToDetail: utils.throttle(function (e) {
  684. let goodsId = e.currentTarget.dataset.id;
  685. wx.navigateTo({
  686. url: "/pages/cart/pages/goodsDetail/goodsDetail?goods_id=" + goodsId
  687. })
  688. }),
  689. //去参团
  690. joinGroup:utils.throttle(function (e){
  691. if (!utils.getStorageSync(storeKeys.TOKEN)) {
  692. wx.navigateTo({
  693. url: "/pages/tabBar/login/login"
  694. })
  695. return;
  696. }
  697. let {
  698. id
  699. } = e.currentTarget.dataset;
  700. console.log(id);
  701. let path = this.data.isfission ? "/pages/activity/pages/groupShopping/groupFission/groupFission?shareId=": "/pages/activity/pages/groupShopping/groupShopping/groupShopping?shareId=";
  702. path = path + id
  703. wx.navigateTo({
  704. url: path
  705. })
  706. }),
  707. //前往原商详
  708. goDetail() {
  709. let goodsId = this.data.goodsId;
  710. wx.navigateTo({
  711. url: "/pages/cart/pages/goodsDetail/goodsDetail?goods_id=" + goodsId
  712. })
  713. },
  714. //发起拼团
  715. goGroupBuy:utils.throttle(function (e){
  716. if (!utils.getStorageSync(storeKeys.TOKEN)) {
  717. wx.navigateTo({
  718. url: "/pages/tabBar/login/login"
  719. })
  720. return;
  721. }
  722. // let index = e.currentTarget? e.currentTarget.dataset.index : e;
  723. let {
  724. index
  725. } = e.currentTarget.dataset;
  726. if(index == 0){//查看
  727. let joinid = this.data.joinid || '';
  728. let path = this.data.isfission ? "/pages/activity/pages/groupShopping/groupFission/groupFission?shareId=": "/pages/activity/pages/groupShopping/groupShopping/groupShopping?shareId=";
  729. path = path + joinid
  730. wx.navigateTo({
  731. url: path
  732. })
  733. }else{//发起
  734. let staffUserId = this.data.shareId || utils.getStorageSync(storeKeys.APPLESID) || 0;
  735. console.log("分享人id" + staffUserId)
  736. // console.log(isfission)
  737. let mode = this.data.isfission ?"groupbuylb":"groupbuy"
  738. console.log(mode)
  739. let data = {
  740. mode: mode,
  741. goodsId: this.data.goodsId, //商品ID
  742. addressId: this.data.addressId || 0,
  743. goodsSkuId: this.data.details.goods_sku_id || 0, //商品规格ID
  744. delivery:10,
  745. activityId: parseInt(this.data.activity_id), //分享人id,
  746. goodsNum: 1,
  747. };
  748. let url = "/pages/activity/pages/groupShopping/groupConfirmOrder/confirmOrder?data=" + JSON.stringify(data);
  749. console.log(JSON.stringify(data));
  750. let template_id = 'QfKtAZax5fw8oEgPbcky_bk2QD4Q4pwj60igE57jHnk';//拼团模板id
  751. // isfission 存在则是裂变拼团
  752. if(this.data.isfission){
  753. template_id = 'M4Nw40B4Hpn4C8NkCiBDajEqz1St_CRRjGlkxDOVP1g';//拼团裂变模板id
  754. }
  755. wx.requestSubscribeMessage({
  756. tmplIds: [template_id],
  757. success (res) {
  758. let status = res[template_id];
  759. // console.log(status)
  760. if(status==='accept'){//允许
  761. console.log('允许推送')
  762. app.noticePush({template_id});
  763. }
  764. if(status==='reject'){//拒绝
  765. console.log('拒绝推送')
  766. app.cancelPush({template_id});
  767. }
  768. },
  769. complete (res){
  770. app.navigateToUrl(url);
  771. }
  772. })
  773. }
  774. }),
  775. })