prod.js 41 KB

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