prod.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699
  1. // pages/prod/prod.js
  2. const app = getApp();
  3. var http = require('../../utils/http.js');
  4. var config = require('../../utils/config.js');
  5. var util = require('../../utils/util.js');
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. tab:0,
  12. list:[],//相似商品和一起买
  13. shopId: 1,
  14. shopName: '',
  15. picDomain: config.picDomain,
  16. indicatorDots: true,
  17. indicatorColor: '#f2f2f2',
  18. indicatorActiveColor: '#006CE8',
  19. isAuthInfo: true,
  20. autoplay: true,
  21. interval: 3000,
  22. duration: 1000,
  23. prodNum: 1,
  24. totalCartNum: 0,
  25. groupActivityId: 0,
  26. pic: "",
  27. imgs: '',
  28. prodName: '',
  29. price: 0,
  30. actPrice: 0,
  31. content: '',
  32. prodId: 0,
  33. brief: '',
  34. halfTitle: '',
  35. brandName:'',
  36. skuId: 0,
  37. popupShow: false,
  38. // 是否获取过用户领取过的优惠券id
  39. loadCouponIds: false,
  40. skuShow: false,
  41. skuGroupShow: false,
  42. commentShow: false,
  43. couponList: [],
  44. skuList: [],
  45. skuGroup: {},
  46. findSku: true,
  47. defaultSku: undefined,
  48. detaultGroupSku: undefined,
  49. selectedProp: [],
  50. selectedPropObj: {},
  51. selectedProperties: "",
  52. propKeys: [],
  53. allProperties: [],
  54. prodCommData: {},
  55. prodCommPage: {
  56. current: 0,
  57. pages: 0,
  58. records: []
  59. },
  60. isAll:false,
  61. prodList: [],
  62. pages: 0,
  63. current: 1,
  64. littleCommPage: [],
  65. commStatus: -1,
  66. isCollection: false,
  67. shareShow: false,
  68. isDist: false, //是否分销员
  69. isDistProd: false, //是否分销商品
  70. distributionCardNo: "", //分销员卡号
  71. wxCodeShow: false, //是否显示二维码弹层
  72. shareWxCode: "", //分享二维码图片路径
  73. groupActivity: {}, // 团购活动
  74. endOfGroupTime: {}, // 距离团购活动结束还剩多久
  75. joinGroupList: [], // 可加入的团列表
  76. skuShowType: 0, // sku的显示类型 0普通sku 1拼团sku
  77. totalStocks: 0, // 活动剩余库存
  78. hasMaxNum: false, // 是否限购
  79. maxNum: 0, // 限购数量
  80. joinGroupListTimer: '',
  81. endOfGroupTimer: '',
  82. scene: '',
  83. prodDiscountList: [], // 商品促销活动列表
  84. phoneNumber: '', //客服电话
  85. showBacktop: false, //回到顶部显隐
  86. showDiscountPopup: false, //促销弹窗显隐
  87. videoContext: '', // 视频组件
  88. isPlaying: false, // 视频是否播放中
  89. currentSwiper: 0, // 当前轮播index
  90. animateInfo:{
  91. startX:99999,
  92. startY:0,
  93. endX:0,
  94. endY:0,
  95. },
  96. move:false
  97. },
  98. /**
  99. * 生命周期函数--监听页面加载
  100. */
  101. onLoad: function (options) {
  102. console.log(options)
  103. //根据Ticket获取保存的内容(pc团购扫码 || 分销)
  104. if (options.scene) {
  105. this.setData({
  106. scene: options.scene,
  107. })
  108. this.getContent() //根据Ticket获取保存的内容
  109. }
  110. if(options.shopid){
  111. this.setData({
  112. shopId: Number(options.shopid) ,
  113. });
  114. }
  115. // 加载商品信息
  116. if (options.prodid) {
  117. this.setData({
  118. prodId: options.prodid,
  119. });
  120. this.executionFunction() //所有需要加载的函数
  121. }
  122. if (options.cardno && options.type == 2) {
  123. // this.bindDistUser(options.cardno)
  124. this.setData({
  125. distributionCardNo: options.cardno,
  126. })
  127. }
  128. this.getCartCount() //请求购物车数量
  129. },
  130. /**
  131. * 执行函数
  132. */
  133. executionFunction: function () {
  134. // 加载评论数据
  135. this.getProdCommData();
  136. // 加载评论项
  137. this.getLittleProdComm();
  138. // 获取商品是否被收藏信息
  139. this.getCollection();
  140. // 查询分销开关是否开启
  141. this.getDistInfo();
  142. //加载商品数据
  143. this.getProdInfo();
  144. // 获取商品所有促销活动
  145. this.getPordDiscountList()
  146. //获取推荐商品
  147. this.getProdRecommended()
  148. // 获取相似商品
  149. this.getSimilarProdList()
  150. },
  151. /**
  152. * 根据Ticket获取保存的内容
  153. */
  154. getContent: function () {
  155. http.request({
  156. url: "/qrcodeTicket/getContent",
  157. method: "GET",
  158. data: {
  159. ticket: this.data.scene
  160. },
  161. callBack: (res) => {
  162. console.log(res)
  163. var content = JSON.parse(res.content);
  164. var ids = JSON.parse(content.content)
  165. if (res.type == 1) { //pc团购二维码跳转
  166. this.setData({
  167. prodId: ids.prodId,
  168. groupActivityId: ids.groupActivityId
  169. })
  170. this.executionFunction() //所有需要加载的函数
  171. } else if (res.type == 2) { //分销员二维码跳转
  172. this.setData({
  173. prodId: ids.shareProdId,
  174. distributionCardNo: ids.cardNo
  175. })
  176. this.executionFunction() //所有需要加载的函数
  177. }
  178. }
  179. })
  180. },
  181. /**
  182. * 生命周期函数--监听页面卸载
  183. */
  184. onUnload: function () {
  185. clearTimeout(this.data.endOfGroupTimer)
  186. },
  187. handleTab(e){
  188. let tab = e.currentTarget.dataset.tab
  189. if(tab == this.data.tab) return
  190. this.setData({
  191. tab,
  192. list:[]
  193. })
  194. if(tab == 0){//相似商品
  195. this.getSimilarProdList()
  196. }else{
  197. this.getOften()
  198. }
  199. },
  200. /**
  201. * 分销绑定用户
  202. */
  203. // bindDistUser(cardno) {
  204. // var params = {
  205. // url: "/p/distribution/bindUser",
  206. // method: "post",
  207. // data: cardno,
  208. // callBack:res=>{
  209. // console.log('绑定分销员',res)
  210. // }
  211. // }
  212. // http.request(params)
  213. // },
  214. /**
  215. * 查询分销相关信息
  216. */
  217. getDistInfo() {
  218. //查询分销开关是否开启
  219. http.request({
  220. url: "/p/distribution/distributionBasicSet/canDistribution",
  221. method: "GET",
  222. dontTrunLogin: true,
  223. // data: {
  224. // shopId: this.data.shopId,
  225. // },
  226. callBack: (res) => {
  227. if (res == 1) {
  228. this.getIsDistInfo();
  229. }
  230. }
  231. })
  232. },
  233. /**
  234. * 查询用户 是否为分销员
  235. */
  236. getIsDistInfo() {
  237. http.request({
  238. url: "/p/distribution/user/distributionUserInfo",
  239. method: "GET",
  240. callBack: (res) => {
  241. console.log('是否分销员', res)
  242. if (res && res.state == 1) {
  243. this.setData({
  244. isDist: true
  245. });
  246. this.getIsDistProd();
  247. wx.setStorageSync("distCardNo", res.cardNo);
  248. }
  249. }
  250. })
  251. },
  252. /**
  253. * 查询是否为分销商品
  254. */
  255. getIsDistProd() {
  256. http.request({
  257. url: "/p/distribution/prod/isDistributionProd",
  258. method: "GET",
  259. data: {
  260. prodId: this.data.prodId,
  261. },
  262. callBack: (res) => {
  263. console.log('是否分销商品', res)
  264. if (res) {
  265. this.setData({
  266. isDistProd: true
  267. });
  268. }
  269. }
  270. })
  271. },
  272. /**
  273. * 获取商品是否被收藏信息
  274. */
  275. getCollection() {
  276. wx.showLoading();
  277. var params = {
  278. url: "/p/user/collection/isCollection",
  279. method: "GET",
  280. dontTrunLogin: true,
  281. data: {
  282. prodId: this.data.prodId
  283. },
  284. callBack: (res) => {
  285. this.setData({
  286. isCollection: res
  287. })
  288. wx.hideLoading();
  289. }
  290. };
  291. http.request(params);
  292. },
  293. /**
  294. * 添加或者取消收藏商品
  295. */
  296. addOrCannelCollection() {
  297. util.checkAuthInfo(() => {
  298. var params = {
  299. url: "/p/user/collection/addOrCancel",
  300. method: "POST",
  301. data: this.data.prodId,
  302. callBack: (res) => {
  303. this.setData({
  304. isCollection: !this.data.isCollection
  305. })
  306. wx.showToast({
  307. title: res ? '已添加收藏' : '已取消收藏',
  308. duration: 3000,
  309. icon: 'none',
  310. })
  311. setTimeout(() => {
  312. wx.hideToast()
  313. }, 3000)
  314. }
  315. };
  316. http.request(params);
  317. })
  318. },
  319. // 获取商品信息
  320. getProdInfo() {
  321. wx.showLoading();
  322. var params = {
  323. url: "/prod/prodInfo",
  324. method: "GET",
  325. data: {
  326. prodId: this.data.prodId,
  327. channelId:wx.getStorageSync('channelId')||3,
  328. shopId:this.data.shopId
  329. // userType: 0
  330. },
  331. callBack: (res) => {
  332. let pic = ''
  333. var imgStrs = res.imgs;
  334. if(imgStrs){
  335. var imgs = imgStrs.split(",");
  336. }
  337. var content = res.content?util.formatHtml(res.content):'';
  338. if(res.pic){
  339. pic = res.pic.split(',')
  340. res.pic = pic[0]
  341. }
  342. this.setData({
  343. imgs: imgs,
  344. content: content,
  345. price: res.price,
  346. prodName: res.prodName,
  347. prodId: res.prodId,
  348. brief: res.brief,
  349. halfTitle: res.halfTitle,
  350. brandName: res.brandName,
  351. totalStocks: res.totalStocks,
  352. // skuId: res.skuId
  353. skuList: res.skuList,
  354. pic: res.pic,
  355. // shopId: res.shopId,
  356. video: res.video,
  357. prodType: res.prodType
  358. });
  359. if (res.video) {
  360. this.getVideoInfo()
  361. }
  362. // 团购商品
  363. if (res.prodType === 1) {
  364. this.setData({
  365. groupActivityId: res.activityId
  366. });
  367. this.getGroupActivity();
  368. this.getJoinGroupList();
  369. }
  370. // 获取优惠券
  371. this.getCouponList();
  372. // 组装sku
  373. res.skuList&&this.groupSkuProp(res.skuList);
  374. this.getShopInfo();
  375. wx.hideLoading();
  376. },
  377. errCallBack: (err) => {
  378. console.log(err)
  379. if (err.statusCode == 400) {
  380. wx.showModal({
  381. title: '提示',
  382. content: err.data,
  383. showCancel: false,
  384. success: (res) => {
  385. if (res.confirm) {
  386. wx.navigateBack({
  387. delta: 1
  388. })
  389. }
  390. }
  391. })
  392. }
  393. }
  394. };
  395. http.request(params);
  396. },
  397. /**
  398. * 获取店铺信息
  399. */
  400. getShopInfo() {
  401. http.request({
  402. url: "/shop/headInfo",
  403. method: "GET",
  404. data: {
  405. shopId: this.data.shopId,
  406. },
  407. callBack: (res) => {
  408. this.setData({
  409. shopName: res.shopName,
  410. shopLogo: res.shopLogo,
  411. phoneNumber: res.tel
  412. })
  413. }
  414. })
  415. },
  416. getProdCommData() {
  417. http.request({
  418. url: "/p/prodComm/commentCount",
  419. method: "GET",
  420. data: {
  421. prodId: this.data.prodId,
  422. channelId:wx.getStorageSync('channelId')||3,
  423. shopId:this.data.shopId
  424. },
  425. callBack: (res) => {
  426. this.setData({
  427. prodCommData: res
  428. })
  429. }
  430. })
  431. },
  432. // 获取部分评论
  433. getLittleProdComm() {
  434. if (this.data.prodCommPage.records.length) {
  435. return;
  436. }
  437. this.getProdCommPage();
  438. },
  439. getMoreCommPage(e) {
  440. this.getProdCommPage();
  441. },
  442. // 获取分页获取评论
  443. getProdCommPage(e) {
  444. if (e) {
  445. if (e.currentTarget.dataset.commStatus === this.data.commStatus) {
  446. return;
  447. }
  448. this.setData({
  449. prodCommPage: {
  450. current: 0,
  451. pages: 0,
  452. records: []
  453. },
  454. commStatus: e.currentTarget.dataset.commstatus
  455. })
  456. }
  457. let data = {
  458. channelId:wx.getStorageSync('channelId')||3,
  459. prodId: this.data.prodId,
  460. shopId: this.data.shopId,
  461. size: 10,
  462. current: this.data.prodCommPage.current + 1,
  463. }
  464. if(this.data.commStatus !=-1){
  465. data.commStatus = this.data.commStatus
  466. }
  467. http.request({
  468. url: "/p/prodComm/commList",
  469. method: "GET",
  470. data,
  471. callBack: (res) => {
  472. res.records.forEach(item => {
  473. if (item.pics) {
  474. item.pics = item.pics.split(',')
  475. }
  476. })
  477. let records = this.data.prodCommPage.records
  478. records = records.concat(res.records)
  479. this.setData({
  480. prodCommPage: {
  481. current: res.current,
  482. pages: res.pages,
  483. records: records
  484. }
  485. })
  486. // 如果商品详情中没有评论的数据,截取两条到商品详情页商品详情
  487. if (!this.data.littleCommPage.length) {
  488. this.setData({
  489. littleCommPage: records.slice(0, 2)
  490. })
  491. }
  492. }
  493. })
  494. },
  495. /**
  496. * 评论小图点击事件(点击图片显示大图)
  497. */
  498. clickImg: function (e) {
  499. const current = e.currentTarget.dataset.index //获取当前点击的 图片 url
  500. const pics = e.currentTarget.dataset.pics
  501. wx.previewImage({
  502. current: pics[current],
  503. urls: pics
  504. })
  505. },
  506. getCouponList() {
  507. http.request({
  508. url: "/coupon/listByProdId",
  509. method: "GET",
  510. data: {
  511. prodId: this.data.prodId,
  512. shopId: this.data.shopId,
  513. },
  514. callBack: (res) => {
  515. this.setData({
  516. couponList: res
  517. })
  518. }
  519. })
  520. },
  521. // 获取推荐商品
  522. getProdRecommended(){
  523. http.request({
  524. url: "/prod/prodRecommended",
  525. method: "GET",
  526. data: {
  527. current: this.data.current,
  528. size: 10,
  529. },
  530. callBack: (res) => {
  531. if(res.records&&res.records.length){
  532. let prodList = []
  533. let img = ''
  534. res.records.map(e => {
  535. if(e.pic){
  536. img = e.pic.split(',')
  537. e.pic = img[0]
  538. }
  539. })
  540. if (this.data.current == 1) {
  541. prodList = res.records
  542. this.setData({
  543. prodList: res.records,
  544. pages: res.pages,
  545. current: res.current
  546. });
  547. } else {
  548. prodList = this.data.prodList
  549. prodList.push(...res.records)
  550. this.setData({
  551. prodList
  552. })
  553. }
  554. if (prodList.length >= res.total) {
  555. this.setData({
  556. isAll: true
  557. })
  558. }
  559. }
  560. }
  561. })
  562. },
  563. // 获取经常一起买
  564. getOften(){
  565. let that = this
  566. http.request({
  567. url: "/sku/buyTogetherOften",
  568. method: "GET",
  569. data: {
  570. shopId:this.data.shopId,
  571. prodId:this.data.prodId,
  572. channelId:wx.getStorageSync('channelId')||3,
  573. userId:wx.getStorageSync('loginResult').userId||'',
  574. current: 1,
  575. size: 18,
  576. },
  577. callBack: (res) => {
  578. let list = that.splitArrayToPages(res.records)
  579. that.setData({
  580. list
  581. })
  582. }
  583. })
  584. },
  585. // 获取相似商品
  586. getSimilarProdList(){
  587. let that = this
  588. http.request({
  589. url: "/prod/similarProdList",
  590. method: "GET",
  591. data: {
  592. shopId:this.data.shopId,
  593. prodId:this.data.prodId,
  594. channelId:wx.getStorageSync('channelId')||3,
  595. userId:wx.getStorageSync('loginResult').userId||'',
  596. current: 1,
  597. size: 18,
  598. },
  599. callBack: (res) => {
  600. if(res.code == 200){
  601. let list = that.splitArrayToPages(res.data.records)
  602. that.setData({
  603. list
  604. })
  605. }
  606. }
  607. })
  608. },
  609. // 工具函数:拆分数组为「最多3页,每页6个」
  610. splitArrayToPages(arr) {
  611. const pageSize = 6; // 每页6个
  612. const maxPages = 3; // 最多3页
  613. const result = [];
  614. // 循环拆分:最多循环3次(确保只分3页)
  615. for (let i = 0; i < maxPages; i++) {
  616. // 计算当前页的起始索引:i * 6(第0页:0-5,第1页:6-11,第2页:12-17)
  617. const start = i * pageSize;
  618. // 截取当前页元素(不足6个时取剩余所有,超过18个时截取到17索引)
  619. const page = arr.slice(start, start + pageSize);
  620. // 加入结果数组(不足3页时,后续循环会push空数组)
  621. result.push(page);
  622. }
  623. return result;
  624. },
  625. /**
  626. * 跳转到商品详情页
  627. */
  628. toProdPage: function (e) {
  629. var prodid = e.currentTarget.dataset.prodid;
  630. var shopid = e.currentTarget.dataset.shopid;
  631. if (prodid) {
  632. wx.navigateTo({
  633. url: `/pages/prod/prod?prodid=${prodid}&shopid=${shopid}`,
  634. })
  635. }
  636. },
  637. // 点击购物车内加减按钮
  638. handleAdd(e){
  639. // 查看是否授权
  640. util.checkAuthInfo(()=>{
  641. let {num,item,subindex,index,type} = e.currentTarget.dataset
  642. let data = {
  643. "basketId": item.basketId||0,
  644. "count": num,
  645. "distributionCardNo": item.distributionCardNo||'',
  646. "prodId": item.prodId,
  647. "shopId": item.shopId,
  648. "skuId": item.skuId||item.skuList[0].skuId,
  649. channelId:wx.getStorageSync('channelId')||3
  650. }
  651. this.changeCar(data,'handleAdd',index,subindex)
  652. this.addAnimate(e)
  653. })
  654. },
  655. // 点击购物车内加减按钮
  656. handleNum(e){
  657. // 查看是否授权
  658. util.checkAuthInfo(()=>{
  659. let {num,item,type,index} = e.currentTarget.dataset
  660. let data = {
  661. "basketId": item.basketId||0,
  662. "count": num,
  663. "distributionCardNo": item.distributionCardNo||'',
  664. "prodId": item.prodId,
  665. "shopId": item.shopId,
  666. "skuId": item.skuId||item.skuList[0].skuId,
  667. channelId:wx.getStorageSync('channelId')||3
  668. }
  669. this.changeCar(data,'handleNum')
  670. if(type == 'add'){
  671. this.addAnimate(e)
  672. }
  673. })
  674. },
  675. addAnimate(e){
  676. let startX = e.touches[0].clientX-10
  677. let startY = e.touches[0].clientY-10
  678. const query = wx.createSelectorQuery().in(this);
  679. query.select('.cart-footer .car-box').boundingClientRect(cartRect => {
  680. console.log(222222,cartRect);
  681. if (!cartRect) return;
  682. let animateInfo = {
  683. startX,
  684. startY,
  685. endX:cartRect.left,
  686. endY:cartRect.bottom,
  687. }
  688. this.setData({
  689. move:true,
  690. animateInfo
  691. })
  692. console.log(animateInfo);
  693. }).exec();
  694. },
  695. endAnimate(){
  696. let animateInfo = {
  697. startX:9999,
  698. startY:0,
  699. endX:0,
  700. endY:0,
  701. }
  702. this.setData({
  703. move:false,
  704. animateInfo
  705. })
  706. },
  707. // 添加修改购物车数量
  708. changeCar(data,name,index,subIndex) {
  709. var params = {
  710. url: "/p/shopCart/changeItem?t="+new Date().getTime(),
  711. method: "post",
  712. data,
  713. callBack: (res) => {
  714. if(res.code == 500){
  715. wx.showToast({
  716. title: res.msg,
  717. icon:'none'
  718. })
  719. }else{
  720. if(name == 'handleNum'){//加减 为你推荐
  721. this.setData({
  722. totalCartNum: this.data.totalCartNum + this.data.prodNum,
  723. });
  724. }else{//加
  725. let list = this.data.list
  726. list[index][subIndex].prodCount+=1
  727. this.setData({
  728. totalCartNum: this.data.totalCartNum + this.data.prodNum,
  729. list
  730. });
  731. }
  732. }
  733. }
  734. };
  735. http.request(params);
  736. },
  737. /**
  738. * 团购商品详情信息
  739. */
  740. getGroupActivity() {
  741. http.request({
  742. url: "/groupProd/info",
  743. method: "GET",
  744. data: {
  745. prodId: this.data.prodId,
  746. groupActivityId: this.data.groupActivityId,
  747. },
  748. callBack: (res) => {
  749. if (res.success) {
  750. this.setData({
  751. groupActivity: res.obj,
  752. maxNum: res.obj.maxNum,
  753. hasMaxNum: res.obj.hasMaxNum
  754. })
  755. this.setDefaultGroupSku();
  756. this.groupActivityCountdown(res.obj)
  757. } else {
  758. this.setData({
  759. groupActivityId: null
  760. });
  761. }
  762. }
  763. })
  764. },
  765. // 团购倒计时
  766. groupActivityCountdown(groupActivity) {
  767. let endOfGroupTime;
  768. // activityStatus 1 未开始
  769. if (groupActivity.activityStatus === 1) {
  770. endOfGroupTime = util.endOfStartTime(util.dateToTimestamp(groupActivity.startTime), new Date().getTime())
  771. } else {
  772. endOfGroupTime = util.endOfStartTime(new Date().getTime(), util.dateToTimestamp(groupActivity.endTime))
  773. }
  774. this.setData({
  775. endOfGroupTime: endOfGroupTime,
  776. endOfGroupTimer: setTimeout(() => this.groupActivityCountdown(groupActivity), 1000)
  777. })
  778. },
  779. // 可加入的拼团列表
  780. getJoinGroupList() {
  781. http.request({
  782. url: "/groupProd/joinGroupList",
  783. method: "GET",
  784. data: {
  785. prodId: this.data.prodId,
  786. groupActivityId: this.data.groupActivityId,
  787. showSize: 3
  788. },
  789. callBack: (res) => {
  790. this.setData({
  791. joinGroupList: res
  792. })
  793. this.joinGroupListCountdown(res)
  794. }
  795. })
  796. },
  797. joinGroupListCountdown(joinGroupList) {
  798. joinGroupList.forEach(item => {
  799. item.endOfGroupTime = util.endOfStartTime(new Date().getTime(), util.dateToTimestamp(item.endTime))
  800. })
  801. this.setData({
  802. joinGroupList: joinGroupList,
  803. joinGroupListTimer: setTimeout(() => this.joinGroupListCountdown(joinGroupList), 1000)
  804. })
  805. },
  806. //根据sku的属性 分组
  807. groupSkuProp: function (skuList) {
  808. // var skuList = this.data.skuList;
  809. if (skuList.length == 1 && skuList[0].properties == "") {
  810. this.setData({
  811. defaultSku: skuList[0]
  812. });
  813. this.setDefaultGroupSku();
  814. return;
  815. }
  816. var skuGroup = {};
  817. var allProperties = [];
  818. var propKeys = [];
  819. this.setData({
  820. selectedPropObj: {}
  821. });
  822. for (var i = 0; i < skuList.length; i++) {
  823. var defaultSku = this.data.defaultSku;
  824. var isDefault = false;
  825. if (!defaultSku && skuList[i].price == this.data.price) { //找到和商品价格一样的那个SKU,作为默认选中的SKU
  826. defaultSku = skuList[i];
  827. isDefault = true;
  828. this.setData({
  829. defaultSku: defaultSku
  830. });
  831. }
  832. var properties = skuList[i].properties; //版本:公开版;颜色:金色;内存:64GB
  833. allProperties.push(properties);
  834. var propList = properties.split(";"); // ["版本:公开版","颜色:金色","内存:64GB"]
  835. var selectedPropObj = this.data.selectedPropObj;
  836. for (var j = 0; j < propList.length; j++) {
  837. var propval = propList[j].split(":"); //["版本","公开版"]
  838. var props = skuGroup[propval[0]]; //先取出 版本对应的值数组
  839. //如果当前是默认选中的sku,把对应的属性值 组装到selectedProp
  840. if (isDefault) {
  841. propKeys.push(propval[0]);
  842. selectedPropObj[propval[0]] = propval[1];
  843. }
  844. if (props == undefined) {
  845. props = []; //假设还没有版本,新建个新的空数组
  846. props.push(propval[1]); //把 "公开版" 放进空数组
  847. } else {
  848. if (!this.array_contain(props, propval[1])) { //如果数组里面没有"公开版"
  849. props.push(propval[1]); //把 "公开版" 放进数组
  850. }
  851. }
  852. skuGroup[propval[0]] = props; //最后把数据 放回版本对应的值
  853. }
  854. this.setData({
  855. selectedPropObj: selectedPropObj,
  856. propKeys: propKeys
  857. });
  858. }
  859. this.parseSelectedObjToVals();
  860. this.setData({
  861. skuGroup: skuGroup,
  862. allProperties: allProperties
  863. });
  864. this.setDefaultGroupSku();
  865. },
  866. //将已选的 {key:val,key2:val2}转换成 [val,val2]
  867. parseSelectedObjToVals: function () {
  868. var selectedPropObj = this.data.selectedPropObj;
  869. var selectedProperties = "";
  870. var selectedProp = [];
  871. for (var key in selectedPropObj) {
  872. selectedProp.push(selectedPropObj[key]);
  873. selectedProperties += key + ":" + selectedPropObj[key] + ";";
  874. }
  875. selectedProperties = selectedProperties.substring(0, selectedProperties.length - 1);
  876. this.setData({
  877. selectedProp: selectedProp,
  878. selectedProperties: selectedProperties
  879. });
  880. var findSku = false;
  881. for (var i = 0; i < this.data.skuList.length; i++) {
  882. if (this.data.skuList[i].properties == selectedProperties) {
  883. findSku = true;
  884. this.setData({
  885. defaultSku: this.data.skuList[i]
  886. });
  887. break;
  888. }
  889. }
  890. this.setData({
  891. findSku: findSku
  892. });
  893. this.setDefaultGroupSku();
  894. },
  895. //点击选择规格
  896. toChooseItem: function (e) {
  897. var ok = e.currentTarget.dataset.ok;
  898. if (ok == 0) {
  899. return;
  900. }
  901. var val = e.currentTarget.dataset.val;
  902. var key = e.currentTarget.dataset.key;
  903. var selectedPropObj = this.data.selectedPropObj;
  904. selectedPropObj[key] = val;
  905. this.setData({
  906. selectedPropObj: selectedPropObj
  907. });
  908. this.parseSelectedObjToVals();
  909. },
  910. //判断数组是否包含某对象
  911. array_contain: function (array, obj) {
  912. for (var i = 0; i < array.length; i++) {
  913. if (array[i] == obj) //如果要求数据类型也一致,这里可使用恒等号===
  914. return true;
  915. }
  916. return false;
  917. },
  918. /**
  919. * 设置选中的拼团sku
  920. */
  921. setDefaultGroupSku() {
  922. if (this.data.groupActivityId) {
  923. var groupSkuList = this.data.groupActivity.groupSkuList;
  924. if (groupSkuList) {
  925. for (var i = 0; i < groupSkuList.length; i++) {
  926. if (groupSkuList[i].properties == this.data.selectedProperties) {
  927. this.setData({
  928. detaultGroupSku: groupSkuList[i]
  929. });
  930. break;
  931. }
  932. }
  933. }
  934. }
  935. },
  936. /**
  937. * 去凑团
  938. */
  939. toSpellGroupDetail(e) {
  940. const groupTeamId = e.currentTarget.dataset.groupteamid
  941. util.checkAuthInfo(() => {
  942. wx.navigateTo({
  943. url: '/pages/spellGroupDetails/spellGroupDetails?groupTeamId=' + groupTeamId,
  944. })
  945. })
  946. },
  947. /**
  948. * 生命周期函数--监听页面初次渲染完成
  949. */
  950. onReady: function () {
  951. this.videoContext = wx.createVideoContext('myVideo')
  952. },
  953. /**
  954. * 生命周期函数--监听页面显示
  955. */
  956. onShow: function () {
  957. this.getCartCount()
  958. if (this.data.prodType == 1) {
  959. this.getJoinGroupList()
  960. }
  961. },
  962. getCartCount: function () {
  963. var params = {
  964. url: "/p/shopCart/prodCount",
  965. method: "GET",
  966. dontTrunLogin: true,
  967. data: {channelId:wx.getStorageSync('channelId')||3},
  968. callBack: (res) => {
  969. if (res > 0) {
  970. // wx.setTabBarBadge({
  971. // index: 2,
  972. // text: res + "",
  973. // })
  974. var app = getApp();
  975. app.globalData.totalCartCount = res;
  976. } else {
  977. // wx.removeTabBarBadge({
  978. // index: 2
  979. // })
  980. var app = getApp();
  981. app.globalData.totalCartCount = 0;
  982. }
  983. this.setData({
  984. totalCartNum: res
  985. })
  986. }
  987. };
  988. http.request(params);
  989. },
  990. /**
  991. * 阻止滚动
  992. */
  993. preventScorll() {
  994. },
  995. /**
  996. * 页面相关事件处理函数--监听用户下拉动作
  997. */
  998. onPullDownRefresh: function () {
  999. },
  1000. /**
  1001. * 页面上拉触底事件的处理函数
  1002. */
  1003. onReachBottom: function () {
  1004. this.getNextPage()
  1005. },
  1006. // 触底加载下一页
  1007. getNextPage() {
  1008. console.log('getNextPage',this.data.current);
  1009. if (this.data.pages > this.data.current) {
  1010. this.setData({
  1011. current: this.data.current + 1
  1012. })
  1013. this.getProdRecommended()
  1014. } else {
  1015. this.setData({
  1016. isAll: true
  1017. })
  1018. }
  1019. },
  1020. /**
  1021. * 跳转到首页
  1022. */
  1023. toHomePage: function () {
  1024. wx.switchTab({
  1025. url: '/pages/index/index',
  1026. })
  1027. },
  1028. /**
  1029. * 跳转到购物车
  1030. */
  1031. toCartPage: function () {
  1032. wx.switchTab({
  1033. url: '/pages/basket/basket',
  1034. })
  1035. },
  1036. handleContact: function (e) {
  1037. console.log(e.detail, '----路径')
  1038. console.log(e.detail.query, '----参数')
  1039. // this.get_register()
  1040. },
  1041. /**
  1042. * 创建商户
  1043. * @param {*} event
  1044. */
  1045. // get_register: function () {
  1046. // let url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxc032a09413289004&secret=453c5047ae43288f1d015d48df32a5c0'
  1047. // wx.request({
  1048. // url:url,
  1049. // method: 'GET',
  1050. // data: {},
  1051. // header: {
  1052. // 'content-type': 'application/json' // 默认值
  1053. // },
  1054. // success(res) {
  1055. // // console.log(res.data.access_token)
  1056. // wx.request({
  1057. // url: 'https://api.weixin.qq.com/cgi-bin/business/register?access_token='+res.data.access_token,
  1058. // method: 'POST',
  1059. // data: {
  1060. // account_name: "test_shopname",
  1061. // nickname: "苹果",
  1062. // icon_media_id: "png",
  1063. // transfer_to_commkf: true
  1064. // },
  1065. // header: {
  1066. // 'content-type': 'application/json' // 默认值
  1067. // },
  1068. // success(res) {
  1069. // console.log(res.data)
  1070. // }
  1071. // })
  1072. // }
  1073. // })
  1074. // },
  1075. /**
  1076. * 加入购物车
  1077. */
  1078. addToCart: function (event) {
  1079. if(this.data.totalStocks == 0) return
  1080. let skuList = this.data.skuList[0]
  1081. if (skuList.weight > 20000) {
  1082. wx.showToast({
  1083. title: "商品超过20kg,太重咯~",
  1084. icon: "none"
  1085. })
  1086. return;
  1087. }
  1088. if(this.data.totalStocks<0){
  1089. wx.showToast({
  1090. title: "该商品暂无库存~",
  1091. icon: "none"
  1092. })
  1093. return;
  1094. }
  1095. if (this.data.isPlaying) {
  1096. this._stopPlay()
  1097. }
  1098. if (!this.data.skuShow) {
  1099. this.setData({
  1100. skuShow: true
  1101. })
  1102. return
  1103. }
  1104. wx.showLoading({
  1105. mask: true
  1106. });
  1107. // 查看是否授权
  1108. util.checkAuthInfo(this.callChangeItem)
  1109. },
  1110. callChangeItem() {
  1111. wx.showLoading({
  1112. mask: true
  1113. });
  1114. http.request({
  1115. url: "/p/shopCart/changeItem",
  1116. method: "POST",
  1117. data: {
  1118. basketId: 0,
  1119. count: this.data.prodNum,
  1120. prodId: this.data.prodId,
  1121. shopId: this.data.shopId,
  1122. shopName: this.data.shopName,
  1123. skuId: this.data.defaultSku.skuId,
  1124. distributionCardNo: this.data.distributionCardNo,
  1125. channelId:wx.getStorageSync('channelId')||3
  1126. },
  1127. callBack: (res) => {
  1128. wx.hideLoading();
  1129. if(res.code == 500){
  1130. return wx.showToast({
  1131. title: "加入购物车成功",
  1132. icon: "none"
  1133. })
  1134. }
  1135. this.setData({
  1136. totalCartNum: this.data.totalCartNum + this.data.prodNum,
  1137. skuShow: false,
  1138. });
  1139. wx.showToast({
  1140. title: "加入购物车成功",
  1141. icon: "none"
  1142. })
  1143. }
  1144. });
  1145. },
  1146. /**
  1147. * 立即购买
  1148. */
  1149. buyNow: function () {
  1150. if(this.data.totalStocks == 0) return
  1151. let skuList = this.data.skuList[0]
  1152. if (skuList.weight > 20000) {
  1153. wx.showToast({
  1154. title: "商品超过20kg,太重咯~",
  1155. icon: "none"
  1156. })
  1157. return;
  1158. }
  1159. if(this.data.totalStocks<0){
  1160. wx.showToast({
  1161. title: "该商品暂无库存~",
  1162. icon: "none"
  1163. })
  1164. return;
  1165. }
  1166. if (this.data.isPlaying) {
  1167. this._stopPlay()
  1168. }
  1169. if (!this.data.skuShow) {
  1170. this.setData({
  1171. skuShow: true
  1172. })
  1173. return
  1174. }
  1175. wx.showLoading({
  1176. mask: true
  1177. });
  1178. // 查看是否授权
  1179. util.checkAuthInfo(this._buyNowData(this))
  1180. },
  1181. /**
  1182. * 立即购买参数配置
  1183. */
  1184. _buyNowData(ctx) {
  1185. wx.setStorageSync("orderItem", JSON.stringify({
  1186. prodId: ctx.data.prodId,
  1187. skuId: ctx.data.defaultSku.skuId,
  1188. prodCount: ctx.data.prodNum,
  1189. shopId: ctx.data.shopId,
  1190. distributionCardNo: ctx.data.distributionCardNo
  1191. }));
  1192. wx.navigateTo({
  1193. url: '/pages/submit-order/submit-order?orderEntry=1&shopId='+ctx.data.shopId,
  1194. })
  1195. },
  1196. /**
  1197. * 减数量
  1198. */
  1199. onCountMinus: function () {
  1200. var prodNum = this.data.prodNum;
  1201. if (prodNum > 1) {
  1202. this.setData({
  1203. prodNum: prodNum - 1
  1204. });
  1205. }
  1206. },
  1207. /**
  1208. * 加数量
  1209. */
  1210. onCountPlus: function () {
  1211. var prodNum = this.data.prodNum;
  1212. // 判断是否限购
  1213. if (this.data.hasMaxNum) {
  1214. if (prodNum < this.data.totalStocks && prodNum < this.data.maxNum) {
  1215. this.setData({
  1216. prodNum: prodNum + 1
  1217. });
  1218. } else {
  1219. wx.showToast({
  1220. title: '限购' + this.data.maxNum + '件',
  1221. icon: 'none',
  1222. })
  1223. }
  1224. } else {
  1225. if (prodNum < this.data.totalStocks) {
  1226. this.setData({
  1227. prodNum: prodNum + 1
  1228. });
  1229. } else {
  1230. wx.showToast({
  1231. title: '库存不足!',
  1232. icon: 'none'
  1233. })
  1234. }
  1235. }
  1236. },
  1237. /**
  1238. * 用户点击转发
  1239. */
  1240. onShareAppMessage: function (res) {
  1241. if (res.from === 'button') {
  1242. var cardno = wx.getStorageSync("distCardNo");
  1243. return {
  1244. title: this.data.prodName,
  1245. path: `/pages/prod/prod?prodid=${this.data.prodId}&shopid=${this.data.shopId}&cardno=${cardno}&type=${this.data.shareType}`,
  1246. imageUrl: this.data.pic,
  1247. }
  1248. } else {
  1249. return {
  1250. title: this.data.prodName,
  1251. path: `/pages/prod/prod?prodid=${this.data.prodId}&shopid=${this.data.shopId}`
  1252. }
  1253. }
  1254. },
  1255. /**
  1256. * 优惠券
  1257. */
  1258. showPopup: function () {
  1259. if (this.data.loadCouponIds) {
  1260. this.setData({
  1261. popupShow: true
  1262. });
  1263. return;
  1264. }
  1265. http.request({
  1266. url: "/p/myCoupon/listCouponIds",
  1267. method: "GET",
  1268. data: {},
  1269. callBack: (couponIds) => {
  1270. var couponList = this.data.couponList;
  1271. couponList.forEach(coupon => {
  1272. if (couponIds && couponIds.length) {
  1273. // 领取该优惠券数量
  1274. var couponLimit = 0;
  1275. couponIds.forEach(couponId => {
  1276. if (couponId == coupon.couponId) {
  1277. couponLimit++;
  1278. }
  1279. });
  1280. // 小于用户领取优惠券上限,可以领取优惠券
  1281. if (couponLimit < coupon.limitNum) {
  1282. coupon.canReceive = true;
  1283. } else {
  1284. coupon.canReceive = false;
  1285. }
  1286. } else {
  1287. coupon.canReceive = true;
  1288. }
  1289. });
  1290. this.setData({
  1291. couponList: couponList,
  1292. popupShow: true,
  1293. loadCouponIds: true
  1294. })
  1295. }
  1296. })
  1297. },
  1298. showSku: function (e) {
  1299. if (e.currentTarget.dataset.alonebuy == 1) {
  1300. this.setData({
  1301. skuShow: true,
  1302. skuShowType: 0
  1303. });
  1304. } else {
  1305. if (this.data.groupActivityId) {
  1306. this.setData({
  1307. skuShow: true,
  1308. skuShowType: 1
  1309. });
  1310. } else {
  1311. this.setData({
  1312. skuShow: true,
  1313. skuShowType: 0
  1314. });
  1315. }
  1316. }
  1317. },
  1318. showGroupSku: function () {
  1319. if (this.data.isPlaying) {
  1320. this._stopPlay()
  1321. }
  1322. this.setData({
  1323. skuShow: true,
  1324. skuShowType: 1
  1325. });
  1326. },
  1327. showComment: function () {
  1328. this.setData({
  1329. commentShow: true
  1330. });
  1331. },
  1332. closePopup: function () {
  1333. this.setData({
  1334. popupShow: false,
  1335. skuShow: false,
  1336. commentShow: false
  1337. });
  1338. },
  1339. /**
  1340. * 赚字浮层
  1341. */
  1342. onShowShare: function (e) {
  1343. if (this.data.isPlaying) {
  1344. this._stopPlay()
  1345. }
  1346. this.setData({
  1347. shareShow: true,
  1348. shareType: e.currentTarget.dataset.type,
  1349. });
  1350. },
  1351. /**
  1352. * 回到顶部
  1353. */
  1354. backToTop: function () {
  1355. wx.pageScrollTo({
  1356. scrollTop: 0
  1357. })
  1358. },
  1359. /**
  1360. * 监听页面滚动
  1361. */
  1362. onPageScroll: function (e) {
  1363. if (e.scrollTop > 80) {
  1364. this.setData({
  1365. showBacktop: true
  1366. })
  1367. } else if (e.scrollTop < 80) {
  1368. this.setData({
  1369. showBacktop: false
  1370. })
  1371. }
  1372. },
  1373. closeEarn: function () {
  1374. this.setData({
  1375. shareShow: false
  1376. })
  1377. },
  1378. toDistCenterPage: function () {
  1379. wx.navigateTo({
  1380. url: '/pages/dis-center/dis-center',
  1381. })
  1382. },
  1383. /**
  1384. * 生成小程序二维码
  1385. */
  1386. genWeixinCode() {
  1387. wx.showLoading({
  1388. mask: true
  1389. })
  1390. var cardNo = wx.getStorageSync("distCardNo");
  1391. var content = JSON.stringify({
  1392. shareProdId: this.data.prodId,
  1393. cardNo: cardNo,
  1394. })
  1395. http.request({
  1396. url: "/qrcodeTicket/miniQrCode",
  1397. method: "GET",
  1398. responseType: 'arraybuffer',
  1399. data: {
  1400. content: content,
  1401. type: 2
  1402. },
  1403. callBack: (res) => {
  1404. this.setData({
  1405. wxCodeShow: true,
  1406. shareShow: false,
  1407. shareWxCode: "data:image/jpg;base64," + wx.arrayBufferToBase64(res)
  1408. });
  1409. wx.hideLoading();
  1410. }
  1411. })
  1412. console.log('分销员id:' + cardNo)
  1413. },
  1414. /**
  1415. * 关闭二维码弹窗
  1416. */
  1417. closeCodePopup() {
  1418. this.setData({
  1419. wxCodeShow: false
  1420. });
  1421. },
  1422. /**
  1423. * 保存图片至相册
  1424. */
  1425. downloadImg() {
  1426. var ths = this
  1427. var imgSrc = this.data.shareWxCode.slice(22); //base64编码
  1428. var save = wx.getFileSystemManager();
  1429. save.writeFile({
  1430. filePath: wx.env.USER_DATA_PATH + '/分享商品-' + this.data.prodName + '.png',
  1431. data: imgSrc,
  1432. encoding: 'base64',
  1433. success: res => {
  1434. wx.saveImageToPhotosAlbum({
  1435. filePath: wx.env.USER_DATA_PATH + '/分享商品-' + this.data.prodName + '.png',
  1436. success: function (res) {
  1437. wx.showToast({
  1438. title: '保存成功',
  1439. })
  1440. ths.setData({
  1441. wxCodeShow: false
  1442. })
  1443. },
  1444. fail: function (err) {
  1445. wx.showModal({
  1446. title: '提示',
  1447. content: '保存图片需要授予存储权限',
  1448. success: modalRes => {
  1449. if (modalRes.confirm) {
  1450. wx.openSetting({
  1451. success(settingdata) {
  1452. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  1453. console.log('用户权限成功')
  1454. } else {
  1455. console.log('用户取消权限')
  1456. }
  1457. }
  1458. })
  1459. }
  1460. }
  1461. })
  1462. }
  1463. })
  1464. // console.log(res)
  1465. },
  1466. fail: err => {
  1467. // console.log(err)
  1468. }
  1469. })
  1470. },
  1471. /**
  1472. * 获取用户信息
  1473. */
  1474. onGotUserInfo: function (e) {
  1475. if (e.detail.errMsg != "getUserInfo:fail auth deny") {
  1476. this.setData({
  1477. isAuthInfo: true
  1478. });
  1479. http.updateUserInfo();
  1480. }
  1481. },
  1482. /**
  1483. * 确认开团
  1484. */
  1485. groupConfirmOrder: function (e) {
  1486. if (!this.data.findSku) {
  1487. return;
  1488. }
  1489. wx.showLoading({
  1490. mask: true
  1491. });
  1492. this.setData({
  1493. teamId: e.currentTarget.dataset.teamid
  1494. })
  1495. // 查看是否授权
  1496. util.checkAuthInfo(this._groupConfirmParams)
  1497. },
  1498. // 拼团确认订单参数
  1499. _groupConfirmParams() {
  1500. wx.setStorageSync("groupOrderItem", JSON.stringify({
  1501. groupSkuId: this.data.detaultGroupSku.groupSkuId, // this.data.groupSkuId,
  1502. prodCount: this.data.prodNum, // this.data.prodNum,
  1503. groupTeamId: this.data.teamId // this.data.groupTeamId
  1504. }));
  1505. wx.navigateTo({
  1506. url: '/pages/groupConfirmOrder/groupConfirmOrder',
  1507. })
  1508. },
  1509. /**
  1510. * 跳转到店铺页
  1511. */
  1512. toShopPage: function () {
  1513. wx.navigateTo({
  1514. url: '/pages/shopPage/shopPage?shopId=' + this.data.shopId,
  1515. })
  1516. },
  1517. /**
  1518. * 通过商品id获取商品所有促销活动
  1519. */
  1520. getPordDiscountList() {
  1521. http.request({
  1522. url: "/marking/discount/getDiscountByProdId",
  1523. method: "GET",
  1524. data: {
  1525. prodId: this.data.prodId
  1526. },
  1527. callBack: res => {
  1528. this.setData({
  1529. prodDiscountList: res
  1530. })
  1531. }
  1532. })
  1533. },
  1534. /**
  1535. * 促销活动弹窗
  1536. */
  1537. clickDiscount: function () {
  1538. var showDiscountPopup = !this.data.showDiscountPopup
  1539. this.setData({
  1540. showDiscountPopup
  1541. })
  1542. },
  1543. /**
  1544. * 页面从前台变为后台时执行
  1545. */
  1546. onHide: function () {
  1547. this.setData({
  1548. isCollection: false,
  1549. skuShow: false,
  1550. })
  1551. clearTimeout(this.data.joinGroupListTimer)
  1552. },
  1553. /**
  1554. * 视频信息
  1555. */
  1556. getVideoInfo() {
  1557. wx.showLoading()
  1558. wx.request({
  1559. url: this.data.video + '?avinfo',
  1560. success: res => {
  1561. wx.hideLoading()
  1562. let time = Number(res.data.format.duration).toFixed(0)
  1563. this.setData({
  1564. videoDuration: time < 60 ? '00′' + time + '″' : ((parseInt(time / 60) < 10 ? '0' + parseInt(time / 60) : parseInt(time / 60)) + '′' + (time % 60 < 10 ? '0' + time % 60 : time % 60) + '″')
  1565. })
  1566. }
  1567. })
  1568. },
  1569. /**
  1570. * 视频播放/停止按钮
  1571. */
  1572. videoOper() {
  1573. if (this.data.isPlaying) {
  1574. this._stopPlay()
  1575. } else {
  1576. this._startPlay()
  1577. }
  1578. },
  1579. /**
  1580. * 视频播放结束时
  1581. */
  1582. playEnd() {
  1583. this._stopPlay()
  1584. },
  1585. _startPlay() {
  1586. this.setData({
  1587. isPlaying: true,
  1588. })
  1589. this.videoContext.play()
  1590. this.videoContext.seek(0)
  1591. },
  1592. _stopPlay() {
  1593. this.setData({
  1594. isPlaying: false
  1595. })
  1596. this.videoContext.stop()
  1597. this.videoContext.seek(0)
  1598. },
  1599. })