prod.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  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. shopId:this.data.shopId,
  564. channelId:wx.getStorageSync('channelId')||3,
  565. current: this.data.current,
  566. size: 10,
  567. },
  568. callBack: (res) => {
  569. if(res.records&&res.records.length){
  570. let prodList = []
  571. let img = ''
  572. res.records.map(e => {
  573. if(e.pic){
  574. img = e.pic.split(',')
  575. e.pic = img[0]
  576. }
  577. })
  578. if (this.data.current == 1) {
  579. prodList = res.records
  580. this.setData({
  581. prodList: res.records,
  582. pages: res.pages,
  583. current: res.current
  584. });
  585. } else {
  586. prodList = this.data.prodList
  587. prodList.push(...res.records)
  588. this.setData({
  589. prodList
  590. })
  591. }
  592. if (prodList.length >= res.total) {
  593. this.setData({
  594. isAll: true
  595. })
  596. }
  597. }
  598. }
  599. })
  600. },
  601. // 获取经常一起买
  602. getOften(){
  603. let that = this
  604. http.request({
  605. url: "/sku/buyTogetherOften",
  606. method: "GET",
  607. data: {
  608. shopId:this.data.shopId,
  609. prodId:this.data.prodId,
  610. channelId:wx.getStorageSync('channelId')||3,
  611. userId:wx.getStorageSync('loginResult').userId||'',
  612. current: 1,
  613. size: 18,
  614. },
  615. callBack: (res) => {
  616. let list = that.splitArrayToPages(res.records)
  617. that.setData({
  618. list
  619. })
  620. }
  621. })
  622. },
  623. // 获取相似商品
  624. getSimilarProdList(){
  625. let that = this
  626. http.request({
  627. url: "/prod/similarProdList",
  628. method: "GET",
  629. data: {
  630. shopId:this.data.shopId,
  631. prodId:this.data.prodId,
  632. channelId:wx.getStorageSync('channelId')||3,
  633. userId:wx.getStorageSync('loginResult').userId||'',
  634. current: 1,
  635. size: 18,
  636. },
  637. callBack: (res) => {
  638. if(res.code == 200){
  639. let list = that.splitArrayToPages(res.data.records)
  640. that.setData({
  641. list
  642. })
  643. }
  644. }
  645. })
  646. },
  647. // 工具函数:拆分数组为「最多3页,每页6个」
  648. splitArrayToPages(arr) {
  649. const pageSize = 6; // 每页6个
  650. const maxPages = 3; // 最多3页
  651. const result = [];
  652. // 循环拆分:最多循环3次(确保只分3页)
  653. for (let i = 0; i < maxPages; i++) {
  654. // 计算当前页的起始索引:i * 6(第0页:0-5,第1页:6-11,第2页:12-17)
  655. const start = i * pageSize;
  656. // 截取当前页元素(不足6个时取剩余所有,超过18个时截取到17索引)
  657. const page = arr.slice(start, start + pageSize);
  658. // 加入结果数组(不足3页时,后续循环会push空数组)
  659. result.push(page);
  660. }
  661. return result;
  662. },
  663. /**
  664. * 跳转到商品详情页
  665. */
  666. toProdPage: function (e) {
  667. var prodid = e.currentTarget.dataset.prodid;
  668. var shopid = e.currentTarget.dataset.shopid;
  669. if (prodid) {
  670. wx.navigateTo({
  671. url: `/pages/prod/prod?prodid=${prodid}&shopid=${shopid}`,
  672. })
  673. }
  674. },
  675. // 点击购物车内加减按钮
  676. handleAdd(e){
  677. // 查看是否授权
  678. util.checkAuthInfo(()=>{
  679. let {num,item,subindex,index,type} = e.currentTarget.dataset
  680. let data = {
  681. "basketId": item.basketId||0,
  682. "count": num,
  683. "distributionCardNo": item.distributionCardNo||'',
  684. "prodId": item.prodId,
  685. "shopId": item.shopId,
  686. "skuId": item.skuId||item.skuList[0].skuId,
  687. channelId:wx.getStorageSync('channelId')||3
  688. }
  689. this.changeCar(data,'handleAdd',index,subindex)
  690. this.addAnimate(e)
  691. })
  692. },
  693. // 点击购物车内加减按钮
  694. handleNum(e){
  695. // 查看是否授权
  696. util.checkAuthInfo(()=>{
  697. let {num,item,type,index} = e.currentTarget.dataset
  698. let data = {
  699. "basketId": item.basketId||0,
  700. "count": num,
  701. "distributionCardNo": item.distributionCardNo||'',
  702. "prodId": item.prodId,
  703. "shopId": item.shopId,
  704. "skuId": item.skuId||item.skuList[0].skuId,
  705. channelId:wx.getStorageSync('channelId')||3
  706. }
  707. this.changeCar(data,'handleNum')
  708. if(type == 'add'){
  709. this.addAnimate(e)
  710. }
  711. })
  712. },
  713. addAnimate(e){
  714. let startX = e.touches[0].clientX-10
  715. let startY = e.touches[0].clientY-10
  716. const query = wx.createSelectorQuery().in(this);
  717. query.select('.cart-footer .car-box').boundingClientRect(cartRect => {
  718. console.log(222222,cartRect);
  719. if (!cartRect) return;
  720. let animateInfo = {
  721. startX,
  722. startY,
  723. endX:cartRect.left,
  724. endY:cartRect.bottom,
  725. }
  726. this.setData({
  727. move:true,
  728. animateInfo
  729. })
  730. console.log(animateInfo);
  731. }).exec();
  732. },
  733. endAnimate(){
  734. let animateInfo = {
  735. startX:9999,
  736. startY:0,
  737. endX:0,
  738. endY:0,
  739. }
  740. this.setData({
  741. move:false,
  742. animateInfo
  743. })
  744. },
  745. // 添加修改购物车数量
  746. changeCar(data,name,index,subIndex) {
  747. var params = {
  748. url: "/p/shopCart/changeItem?t="+new Date().getTime(),
  749. method: "post",
  750. data,
  751. callBack: (res) => {
  752. if(res.code == 500){
  753. wx.showToast({
  754. title: res.msg,
  755. icon:'none'
  756. })
  757. }else{
  758. if(name == 'handleNum'){//加减 为你推荐
  759. this.setData({
  760. totalCartNum: this.data.totalCartNum + this.data.prodNum,
  761. });
  762. }else{//加
  763. let list = this.data.list
  764. list[index][subIndex].prodCount+=1
  765. this.setData({
  766. totalCartNum: this.data.totalCartNum + this.data.prodNum,
  767. list
  768. });
  769. }
  770. }
  771. }
  772. };
  773. http.request(params);
  774. },
  775. /**
  776. * 团购商品详情信息
  777. */
  778. getGroupActivity() {
  779. http.request({
  780. url: "/groupProd/info",
  781. method: "GET",
  782. data: {
  783. prodId: this.data.prodId,
  784. groupActivityId: this.data.groupActivityId,
  785. },
  786. callBack: (res) => {
  787. if (res.success) {
  788. this.setData({
  789. groupActivity: res.obj,
  790. maxNum: res.obj.maxNum,
  791. hasMaxNum: res.obj.hasMaxNum
  792. })
  793. this.setDefaultGroupSku();
  794. this.groupActivityCountdown(res.obj)
  795. } else {
  796. this.setData({
  797. groupActivityId: null
  798. });
  799. }
  800. }
  801. })
  802. },
  803. // 团购倒计时
  804. groupActivityCountdown(groupActivity) {
  805. let endOfGroupTime;
  806. // activityStatus 1 未开始
  807. if (groupActivity.activityStatus === 1) {
  808. endOfGroupTime = util.endOfStartTime(util.dateToTimestamp(groupActivity.startTime), new Date().getTime())
  809. } else {
  810. endOfGroupTime = util.endOfStartTime(new Date().getTime(), util.dateToTimestamp(groupActivity.endTime))
  811. }
  812. this.setData({
  813. endOfGroupTime: endOfGroupTime,
  814. endOfGroupTimer: setTimeout(() => this.groupActivityCountdown(groupActivity), 1000)
  815. })
  816. },
  817. // 可加入的拼团列表
  818. getJoinGroupList() {
  819. http.request({
  820. url: "/groupProd/joinGroupList",
  821. method: "GET",
  822. data: {
  823. prodId: this.data.prodId,
  824. groupActivityId: this.data.groupActivityId,
  825. showSize: 3
  826. },
  827. callBack: (res) => {
  828. this.setData({
  829. joinGroupList: res
  830. })
  831. this.joinGroupListCountdown(res)
  832. }
  833. })
  834. },
  835. joinGroupListCountdown(joinGroupList) {
  836. joinGroupList.forEach(item => {
  837. item.endOfGroupTime = util.endOfStartTime(new Date().getTime(), util.dateToTimestamp(item.endTime))
  838. })
  839. this.setData({
  840. joinGroupList: joinGroupList,
  841. joinGroupListTimer: setTimeout(() => this.joinGroupListCountdown(joinGroupList), 1000)
  842. })
  843. },
  844. //根据sku的属性 分组
  845. groupSkuProp: function (skuList) {
  846. // var skuList = this.data.skuList;
  847. if (skuList.length == 1 && skuList[0].properties == "") {
  848. this.setData({
  849. defaultSku: skuList[0]
  850. });
  851. this.setDefaultGroupSku();
  852. return;
  853. }
  854. var skuGroup = {};
  855. var allProperties = [];
  856. var propKeys = [];
  857. this.setData({
  858. selectedPropObj: {}
  859. });
  860. for (var i = 0; i < skuList.length; i++) {
  861. var defaultSku = this.data.defaultSku;
  862. var isDefault = false;
  863. if (!defaultSku && skuList[i].price == this.data.price) { //找到和商品价格一样的那个SKU,作为默认选中的SKU
  864. defaultSku = skuList[i];
  865. isDefault = true;
  866. this.setData({
  867. defaultSku: defaultSku
  868. });
  869. }
  870. var properties = skuList[i].properties; //版本:公开版;颜色:金色;内存:64GB
  871. allProperties.push(properties);
  872. var propList = properties.split(";"); // ["版本:公开版","颜色:金色","内存:64GB"]
  873. var selectedPropObj = this.data.selectedPropObj;
  874. for (var j = 0; j < propList.length; j++) {
  875. var propval = propList[j].split(":"); //["版本","公开版"]
  876. var props = skuGroup[propval[0]]; //先取出 版本对应的值数组
  877. //如果当前是默认选中的sku,把对应的属性值 组装到selectedProp
  878. if (isDefault) {
  879. propKeys.push(propval[0]);
  880. selectedPropObj[propval[0]] = propval[1];
  881. }
  882. if (props == undefined) {
  883. props = []; //假设还没有版本,新建个新的空数组
  884. props.push(propval[1]); //把 "公开版" 放进空数组
  885. } else {
  886. if (!this.array_contain(props, propval[1])) { //如果数组里面没有"公开版"
  887. props.push(propval[1]); //把 "公开版" 放进数组
  888. }
  889. }
  890. skuGroup[propval[0]] = props; //最后把数据 放回版本对应的值
  891. }
  892. this.setData({
  893. selectedPropObj: selectedPropObj,
  894. propKeys: propKeys
  895. });
  896. }
  897. this.parseSelectedObjToVals();
  898. this.setData({
  899. skuGroup: skuGroup,
  900. allProperties: allProperties
  901. });
  902. this.setDefaultGroupSku();
  903. },
  904. //将已选的 {key:val,key2:val2}转换成 [val,val2]
  905. parseSelectedObjToVals: function () {
  906. var selectedPropObj = this.data.selectedPropObj;
  907. var selectedProperties = "";
  908. var selectedProp = [];
  909. for (var key in selectedPropObj) {
  910. selectedProp.push(selectedPropObj[key]);
  911. selectedProperties += key + ":" + selectedPropObj[key] + ";";
  912. }
  913. selectedProperties = selectedProperties.substring(0, selectedProperties.length - 1);
  914. this.setData({
  915. selectedProp: selectedProp,
  916. selectedProperties: selectedProperties
  917. });
  918. var findSku = false;
  919. for (var i = 0; i < this.data.skuList.length; i++) {
  920. if (this.data.skuList[i].properties == selectedProperties) {
  921. findSku = true;
  922. this.setData({
  923. defaultSku: this.data.skuList[i]
  924. });
  925. break;
  926. }
  927. }
  928. this.setData({
  929. findSku: findSku
  930. });
  931. this.setDefaultGroupSku();
  932. },
  933. //点击选择规格
  934. toChooseItem: function (e) {
  935. var ok = e.currentTarget.dataset.ok;
  936. if (ok == 0) {
  937. return;
  938. }
  939. var val = e.currentTarget.dataset.val;
  940. var key = e.currentTarget.dataset.key;
  941. var selectedPropObj = this.data.selectedPropObj;
  942. selectedPropObj[key] = val;
  943. this.setData({
  944. selectedPropObj: selectedPropObj
  945. });
  946. this.parseSelectedObjToVals();
  947. },
  948. //判断数组是否包含某对象
  949. array_contain: function (array, obj) {
  950. for (var i = 0; i < array.length; i++) {
  951. if (array[i] == obj) //如果要求数据类型也一致,这里可使用恒等号===
  952. return true;
  953. }
  954. return false;
  955. },
  956. /**
  957. * 设置选中的拼团sku
  958. */
  959. setDefaultGroupSku() {
  960. if (this.data.groupActivityId) {
  961. var groupSkuList = this.data.groupActivity.groupSkuList;
  962. if (groupSkuList) {
  963. for (var i = 0; i < groupSkuList.length; i++) {
  964. if (groupSkuList[i].properties == this.data.selectedProperties) {
  965. this.setData({
  966. detaultGroupSku: groupSkuList[i]
  967. });
  968. break;
  969. }
  970. }
  971. }
  972. }
  973. },
  974. /**
  975. * 去凑团
  976. */
  977. toSpellGroupDetail(e) {
  978. const groupTeamId = e.currentTarget.dataset.groupteamid
  979. util.checkAuthInfo(() => {
  980. wx.navigateTo({
  981. url: '/pages/spellGroupDetails/spellGroupDetails?groupTeamId=' + groupTeamId,
  982. })
  983. })
  984. },
  985. /**
  986. * 生命周期函数--监听页面初次渲染完成
  987. */
  988. onReady: function () {
  989. this.videoContext = wx.createVideoContext('myVideo')
  990. },
  991. /**
  992. * 生命周期函数--监听页面显示
  993. */
  994. onShow: function () {
  995. this.getCartCount()
  996. if (this.data.prodType == 1) {
  997. this.getJoinGroupList()
  998. }
  999. },
  1000. getCartCount: function () {
  1001. var params = {
  1002. url: "/p/shopCart/prodCount",
  1003. method: "GET",
  1004. dontTrunLogin: true,
  1005. data: {channelId:wx.getStorageSync('channelId')||3},
  1006. callBack: (res) => {
  1007. if (res > 0) {
  1008. // wx.setTabBarBadge({
  1009. // index: 2,
  1010. // text: res + "",
  1011. // })
  1012. var app = getApp();
  1013. app.globalData.totalCartCount = res;
  1014. } else {
  1015. // wx.removeTabBarBadge({
  1016. // index: 2
  1017. // })
  1018. var app = getApp();
  1019. app.globalData.totalCartCount = 0;
  1020. }
  1021. this.setData({
  1022. totalCartNum: res
  1023. })
  1024. }
  1025. };
  1026. http.request(params);
  1027. },
  1028. /**
  1029. * 阻止滚动
  1030. */
  1031. preventScorll() {
  1032. },
  1033. /**
  1034. * 页面相关事件处理函数--监听用户下拉动作
  1035. */
  1036. onPullDownRefresh: function () {
  1037. },
  1038. /**
  1039. * 页面上拉触底事件的处理函数
  1040. */
  1041. onReachBottom: function () {
  1042. this.getNextPage()
  1043. },
  1044. // 触底加载下一页
  1045. getNextPage() {
  1046. console.log('getNextPage',this.data.current);
  1047. if (this.data.pages > this.data.current) {
  1048. this.setData({
  1049. current: this.data.current + 1
  1050. })
  1051. this.getProdRecommended()
  1052. } else {
  1053. this.setData({
  1054. isAll: true
  1055. })
  1056. }
  1057. },
  1058. /**
  1059. * 跳转到首页
  1060. */
  1061. toHomePage: function () {
  1062. wx.switchTab({
  1063. url: '/pages/index/index',
  1064. })
  1065. },
  1066. /**
  1067. * 跳转到购物车
  1068. */
  1069. toCartPage: function () {
  1070. wx.switchTab({
  1071. url: '/pages/basket/basket',
  1072. })
  1073. },
  1074. handleContact: function (e) {
  1075. console.log(e.detail, '----路径')
  1076. console.log(e.detail.query, '----参数')
  1077. // this.get_register()
  1078. },
  1079. /**
  1080. * 创建商户
  1081. * @param {*} event
  1082. */
  1083. // get_register: function () {
  1084. // let url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxc032a09413289004&secret=453c5047ae43288f1d015d48df32a5c0'
  1085. // wx.request({
  1086. // url:url,
  1087. // method: 'GET',
  1088. // data: {},
  1089. // header: {
  1090. // 'content-type': 'application/json' // 默认值
  1091. // },
  1092. // success(res) {
  1093. // // console.log(res.data.access_token)
  1094. // wx.request({
  1095. // url: 'https://api.weixin.qq.com/cgi-bin/business/register?access_token='+res.data.access_token,
  1096. // method: 'POST',
  1097. // data: {
  1098. // account_name: "test_shopname",
  1099. // nickname: "苹果",
  1100. // icon_media_id: "png",
  1101. // transfer_to_commkf: true
  1102. // },
  1103. // header: {
  1104. // 'content-type': 'application/json' // 默认值
  1105. // },
  1106. // success(res) {
  1107. // console.log(res.data)
  1108. // }
  1109. // })
  1110. // }
  1111. // })
  1112. // },
  1113. /**
  1114. * 加入购物车
  1115. */
  1116. addToCart: function (event) {
  1117. if(this.data.totalStocks == 0) return
  1118. let skuList = this.data.skuList[0]
  1119. if (skuList.weight > 20000) {
  1120. wx.showToast({
  1121. title: "商品超过20kg,太重咯~",
  1122. icon: "none"
  1123. })
  1124. return;
  1125. }
  1126. if(this.data.totalStocks<0){
  1127. wx.showToast({
  1128. title: "该商品暂无库存~",
  1129. icon: "none"
  1130. })
  1131. return;
  1132. }
  1133. if (this.data.isPlaying) {
  1134. this._stopPlay()
  1135. }
  1136. if (!this.data.skuShow) {
  1137. this.setData({
  1138. skuShow: true
  1139. })
  1140. return
  1141. }
  1142. wx.showLoading({
  1143. mask: true
  1144. });
  1145. // 查看是否授权
  1146. util.checkAuthInfo(this.callChangeItem)
  1147. },
  1148. callChangeItem() {
  1149. wx.showLoading({
  1150. mask: true
  1151. });
  1152. http.request({
  1153. url: "/p/shopCart/changeItem",
  1154. method: "POST",
  1155. data: {
  1156. basketId: 0,
  1157. count: this.data.prodNum,
  1158. prodId: this.data.prodId,
  1159. shopId: this.data.shopId,
  1160. shopName: this.data.shopName,
  1161. skuId: this.data.defaultSku.skuId,
  1162. distributionCardNo: this.data.distributionCardNo,
  1163. channelId:wx.getStorageSync('channelId')||3
  1164. },
  1165. callBack: (res) => {
  1166. wx.hideLoading();
  1167. if(res.code == 500){
  1168. return wx.showToast({
  1169. title: "加入购物车成功",
  1170. icon: "none"
  1171. })
  1172. }
  1173. this.setData({
  1174. totalCartNum: this.data.totalCartNum + this.data.prodNum,
  1175. skuShow: false,
  1176. });
  1177. wx.showToast({
  1178. title: "加入购物车成功",
  1179. icon: "none"
  1180. })
  1181. }
  1182. });
  1183. },
  1184. /**
  1185. * 立即购买
  1186. */
  1187. buyNow: function () {
  1188. if(this.data.totalStocks == 0) return
  1189. let skuList = this.data.skuList[0]
  1190. if (skuList.weight > 20000) {
  1191. wx.showToast({
  1192. title: "商品超过20kg,太重咯~",
  1193. icon: "none"
  1194. })
  1195. return;
  1196. }
  1197. if(this.data.totalStocks<0){
  1198. wx.showToast({
  1199. title: "该商品暂无库存~",
  1200. icon: "none"
  1201. })
  1202. return;
  1203. }
  1204. if (this.data.isPlaying) {
  1205. this._stopPlay()
  1206. }
  1207. if (!this.data.skuShow) {
  1208. this.setData({
  1209. skuShow: true
  1210. })
  1211. return
  1212. }
  1213. wx.showLoading({
  1214. mask: true
  1215. });
  1216. // 查看是否授权
  1217. util.checkAuthInfo(this._buyNowData(this))
  1218. },
  1219. /**
  1220. * 立即购买参数配置
  1221. */
  1222. _buyNowData(ctx) {
  1223. wx.setStorageSync("orderItem", JSON.stringify({
  1224. prodId: ctx.data.prodId,
  1225. skuId: ctx.data.defaultSku.skuId,
  1226. prodCount: ctx.data.prodNum,
  1227. shopId: ctx.data.shopId,
  1228. distributionCardNo: ctx.data.distributionCardNo
  1229. }));
  1230. wx.navigateTo({
  1231. url: '/pages/submit-order/submit-order?orderEntry=1&shopId='+ctx.data.shopId,
  1232. })
  1233. },
  1234. /**
  1235. * 减数量
  1236. */
  1237. onCountMinus: function () {
  1238. var prodNum = this.data.prodNum;
  1239. if (prodNum > 1) {
  1240. this.setData({
  1241. prodNum: prodNum - 1
  1242. });
  1243. }
  1244. },
  1245. /**
  1246. * 加数量
  1247. */
  1248. onCountPlus: function () {
  1249. var prodNum = this.data.prodNum;
  1250. // 判断是否限购
  1251. if (this.data.hasMaxNum) {
  1252. if (prodNum < this.data.totalStocks && prodNum < this.data.maxNum) {
  1253. this.setData({
  1254. prodNum: prodNum + 1
  1255. });
  1256. } else {
  1257. wx.showToast({
  1258. title: '限购' + this.data.maxNum + '件',
  1259. icon: 'none',
  1260. })
  1261. }
  1262. } else {
  1263. if (prodNum < this.data.totalStocks) {
  1264. this.setData({
  1265. prodNum: prodNum + 1
  1266. });
  1267. } else {
  1268. wx.showToast({
  1269. title: '库存不足!',
  1270. icon: 'none'
  1271. })
  1272. }
  1273. }
  1274. },
  1275. /**
  1276. * 用户点击转发
  1277. */
  1278. onShareAppMessage: function (res) {
  1279. if (res.from === 'button') {
  1280. var cardno = wx.getStorageSync("distCardNo");
  1281. return {
  1282. title: this.data.prodName,
  1283. path: `/pages/prod/prod?prodid=${this.data.prodId}&shopid=${this.data.shopId}&cardno=${cardno}&type=${this.data.shareType}`,
  1284. imageUrl: this.data.pic,
  1285. }
  1286. } else {
  1287. return {
  1288. title: this.data.prodName,
  1289. path: `/pages/prod/prod?prodid=${this.data.prodId}&shopid=${this.data.shopId}`
  1290. }
  1291. }
  1292. },
  1293. /**
  1294. * 优惠券
  1295. */
  1296. showPopup: function () {
  1297. if (this.data.loadCouponIds) {
  1298. this.setData({
  1299. popupShow: true
  1300. });
  1301. return;
  1302. }
  1303. http.request({
  1304. url: "/p/myCoupon/listCouponIds",
  1305. method: "GET",
  1306. data: {},
  1307. callBack: (couponIds) => {
  1308. var couponList = this.data.couponList;
  1309. couponList.forEach(coupon => {
  1310. if (couponIds && couponIds.length) {
  1311. // 领取该优惠券数量
  1312. var couponLimit = 0;
  1313. couponIds.forEach(couponId => {
  1314. if (couponId == coupon.couponId) {
  1315. couponLimit++;
  1316. }
  1317. });
  1318. // 小于用户领取优惠券上限,可以领取优惠券
  1319. if (couponLimit < coupon.limitNum) {
  1320. coupon.canReceive = true;
  1321. } else {
  1322. coupon.canReceive = false;
  1323. }
  1324. } else {
  1325. coupon.canReceive = true;
  1326. }
  1327. });
  1328. this.setData({
  1329. couponList: couponList,
  1330. popupShow: true,
  1331. loadCouponIds: true
  1332. })
  1333. }
  1334. })
  1335. },
  1336. showSku: function (e) {
  1337. if (e.currentTarget.dataset.alonebuy == 1) {
  1338. this.setData({
  1339. skuShow: true,
  1340. skuShowType: 0
  1341. });
  1342. } else {
  1343. if (this.data.groupActivityId) {
  1344. this.setData({
  1345. skuShow: true,
  1346. skuShowType: 1
  1347. });
  1348. } else {
  1349. this.setData({
  1350. skuShow: true,
  1351. skuShowType: 0
  1352. });
  1353. }
  1354. }
  1355. },
  1356. showGroupSku: function () {
  1357. if (this.data.isPlaying) {
  1358. this._stopPlay()
  1359. }
  1360. this.setData({
  1361. skuShow: true,
  1362. skuShowType: 1
  1363. });
  1364. },
  1365. showComment: function () {
  1366. this.setData({
  1367. commentShow: true
  1368. });
  1369. },
  1370. closePopup: function () {
  1371. this.setData({
  1372. popupShow: false,
  1373. skuShow: false,
  1374. commentShow: false
  1375. });
  1376. },
  1377. /**
  1378. * 赚字浮层
  1379. */
  1380. onShowShare: function (e) {
  1381. if (this.data.isPlaying) {
  1382. this._stopPlay()
  1383. }
  1384. this.setData({
  1385. shareShow: true,
  1386. shareType: e.currentTarget.dataset.type,
  1387. });
  1388. },
  1389. /**
  1390. * 回到顶部
  1391. */
  1392. backToTop: function () {
  1393. wx.pageScrollTo({
  1394. scrollTop: 0
  1395. })
  1396. },
  1397. /**
  1398. * 监听页面滚动
  1399. */
  1400. onPageScroll: function (e) {
  1401. if (e.scrollTop > 80) {
  1402. this.setData({
  1403. showBacktop: true
  1404. })
  1405. } else if (e.scrollTop < 80) {
  1406. this.setData({
  1407. showBacktop: false
  1408. })
  1409. }
  1410. if(e.scrollTop > 400){
  1411. let active = 1
  1412. if(e.scrollTop<659){
  1413. active = 1
  1414. }else if(e.scrollTop>659){
  1415. active = 2
  1416. }
  1417. this.setData({
  1418. opacity:1,
  1419. active
  1420. })
  1421. }else {
  1422. let opacity = 1
  1423. if(e.scrollTop < 400&&e.scrollTop > 300){
  1424. opacity = .6
  1425. }else if(e.scrollTop < 300&&e.scrollTop > 100){
  1426. opacity = .4
  1427. }else{
  1428. opacity = 0
  1429. }
  1430. this.setData({
  1431. opacity,
  1432. active:0
  1433. })
  1434. }
  1435. },
  1436. closeEarn: function () {
  1437. this.setData({
  1438. shareShow: false
  1439. })
  1440. },
  1441. toDistCenterPage: function () {
  1442. wx.navigateTo({
  1443. url: '/pages/dis-center/dis-center',
  1444. })
  1445. },
  1446. /**
  1447. * 生成小程序二维码
  1448. */
  1449. genWeixinCode() {
  1450. wx.showLoading({
  1451. mask: true
  1452. })
  1453. var cardNo = wx.getStorageSync("distCardNo");
  1454. var content = JSON.stringify({
  1455. shareProdId: this.data.prodId,
  1456. cardNo: cardNo,
  1457. })
  1458. http.request({
  1459. url: "/qrcodeTicket/miniQrCode",
  1460. method: "GET",
  1461. responseType: 'arraybuffer',
  1462. data: {
  1463. content: content,
  1464. type: 2
  1465. },
  1466. callBack: (res) => {
  1467. this.setData({
  1468. wxCodeShow: true,
  1469. shareShow: false,
  1470. shareWxCode: "data:image/jpg;base64," + wx.arrayBufferToBase64(res)
  1471. });
  1472. wx.hideLoading();
  1473. }
  1474. })
  1475. console.log('分销员id:' + cardNo)
  1476. },
  1477. /**
  1478. * 关闭二维码弹窗
  1479. */
  1480. closeCodePopup() {
  1481. this.setData({
  1482. wxCodeShow: false
  1483. });
  1484. },
  1485. /**
  1486. * 保存图片至相册
  1487. */
  1488. downloadImg() {
  1489. var ths = this
  1490. var imgSrc = this.data.shareWxCode.slice(22); //base64编码
  1491. var save = wx.getFileSystemManager();
  1492. save.writeFile({
  1493. filePath: wx.env.USER_DATA_PATH + '/分享商品-' + this.data.prodName + '.png',
  1494. data: imgSrc,
  1495. encoding: 'base64',
  1496. success: res => {
  1497. wx.saveImageToPhotosAlbum({
  1498. filePath: wx.env.USER_DATA_PATH + '/分享商品-' + this.data.prodName + '.png',
  1499. success: function (res) {
  1500. wx.showToast({
  1501. title: '保存成功',
  1502. })
  1503. ths.setData({
  1504. wxCodeShow: false
  1505. })
  1506. },
  1507. fail: function (err) {
  1508. wx.showModal({
  1509. title: '提示',
  1510. content: '保存图片需要授予存储权限',
  1511. success: modalRes => {
  1512. if (modalRes.confirm) {
  1513. wx.openSetting({
  1514. success(settingdata) {
  1515. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  1516. console.log('用户权限成功')
  1517. } else {
  1518. console.log('用户取消权限')
  1519. }
  1520. }
  1521. })
  1522. }
  1523. }
  1524. })
  1525. }
  1526. })
  1527. // console.log(res)
  1528. },
  1529. fail: err => {
  1530. // console.log(err)
  1531. }
  1532. })
  1533. },
  1534. /**
  1535. * 获取用户信息
  1536. */
  1537. onGotUserInfo: function (e) {
  1538. if (e.detail.errMsg != "getUserInfo:fail auth deny") {
  1539. this.setData({
  1540. isAuthInfo: true
  1541. });
  1542. http.updateUserInfo();
  1543. }
  1544. },
  1545. /**
  1546. * 确认开团
  1547. */
  1548. groupConfirmOrder: function (e) {
  1549. if (!this.data.findSku) {
  1550. return;
  1551. }
  1552. wx.showLoading({
  1553. mask: true
  1554. });
  1555. this.setData({
  1556. teamId: e.currentTarget.dataset.teamid
  1557. })
  1558. // 查看是否授权
  1559. util.checkAuthInfo(this._groupConfirmParams)
  1560. },
  1561. // 拼团确认订单参数
  1562. _groupConfirmParams() {
  1563. wx.setStorageSync("groupOrderItem", JSON.stringify({
  1564. groupSkuId: this.data.detaultGroupSku.groupSkuId, // this.data.groupSkuId,
  1565. prodCount: this.data.prodNum, // this.data.prodNum,
  1566. groupTeamId: this.data.teamId // this.data.groupTeamId
  1567. }));
  1568. wx.navigateTo({
  1569. url: '/pages/groupConfirmOrder/groupConfirmOrder',
  1570. })
  1571. },
  1572. /**
  1573. * 跳转到店铺页
  1574. */
  1575. toShopPage: function () {
  1576. wx.navigateTo({
  1577. url: '/pages/shopPage/shopPage?shopId=' + this.data.shopId,
  1578. })
  1579. },
  1580. /**
  1581. * 通过商品id获取商品所有促销活动
  1582. */
  1583. getPordDiscountList() {
  1584. http.request({
  1585. url: "/marking/discount/getDiscountByProdId",
  1586. method: "GET",
  1587. data: {
  1588. prodId: this.data.prodId
  1589. },
  1590. callBack: res => {
  1591. this.setData({
  1592. prodDiscountList: res
  1593. })
  1594. }
  1595. })
  1596. },
  1597. /**
  1598. * 促销活动弹窗
  1599. */
  1600. clickDiscount: function () {
  1601. var showDiscountPopup = !this.data.showDiscountPopup
  1602. this.setData({
  1603. showDiscountPopup
  1604. })
  1605. },
  1606. /**
  1607. * 页面从前台变为后台时执行
  1608. */
  1609. onHide: function () {
  1610. this.setData({
  1611. isCollection: false,
  1612. skuShow: false,
  1613. })
  1614. clearTimeout(this.data.joinGroupListTimer)
  1615. },
  1616. /**
  1617. * 视频信息
  1618. */
  1619. getVideoInfo() {
  1620. wx.showLoading()
  1621. wx.request({
  1622. url: this.data.video + '?avinfo',
  1623. success: res => {
  1624. wx.hideLoading()
  1625. let time = Number(res.data.format.duration).toFixed(0)
  1626. this.setData({
  1627. videoDuration: time < 60 ? '00′' + time + '″' : ((parseInt(time / 60) < 10 ? '0' + parseInt(time / 60) : parseInt(time / 60)) + '′' + (time % 60 < 10 ? '0' + time % 60 : time % 60) + '″')
  1628. })
  1629. }
  1630. })
  1631. },
  1632. /**
  1633. * 视频播放/停止按钮
  1634. */
  1635. videoOper() {
  1636. if (this.data.isPlaying) {
  1637. this._stopPlay()
  1638. } else {
  1639. this._startPlay()
  1640. }
  1641. },
  1642. /**
  1643. * 视频播放结束时
  1644. */
  1645. playEnd() {
  1646. this._stopPlay()
  1647. },
  1648. _startPlay() {
  1649. this.setData({
  1650. isPlaying: true,
  1651. })
  1652. this.videoContext.play()
  1653. this.videoContext.seek(0)
  1654. },
  1655. _stopPlay() {
  1656. this.setData({
  1657. isPlaying: false
  1658. })
  1659. this.videoContext.stop()
  1660. this.videoContext.seek(0)
  1661. },
  1662. })