goods.js 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. var app = getApp();
  2. var WxParse = require('../../lib/wxParse/wxParse.js');
  3. var util = require('../../utils/util.js');
  4. var api = require('../../config/api.js');
  5. var goodsUtil = require('../../utils/goods.js');
  6. Page({
  7. data: {
  8. winHeight: "",
  9. id: 0,
  10. referrer: 0,
  11. goods: {},
  12. gallery: [],
  13. attribute: [],
  14. issueList: [],
  15. comment: [],
  16. brand: {},
  17. specificationList: [],
  18. productList: [],
  19. relatedGoods: [],
  20. cartGoodsCount: 0,
  21. userHasCollect: 0,
  22. crashList: {},
  23. number: 1,
  24. checkedSpecText: '请选择规格数量',
  25. openAttr: false,
  26. openAttrByOrder: false,
  27. noCollectImage: "/static/images/icon_collect.png",
  28. hasCollectImage: "/static/images/icon_collect_checked.png",
  29. collectBackImage: "/static/images/icon_collect.png",
  30. showNavList: false,
  31. stockNum: '',
  32. cartNumber: 0,
  33. autoplay: false,
  34. defaultFreight: 0,
  35. current: 0, //banner当前的index
  36. isPlay: true,
  37. indexNum: 0,
  38. windowWidth: 0,
  39. leftWidth: 0,
  40. startX: 0,
  41. curr_id: '',
  42. videoHiddenName: true,
  43. imgHiddenName: false,
  44. page: 1,
  45. size: 3,
  46. detailContent: '',
  47. storeId: '',
  48. detailStoreId: '',
  49. promId: '',
  50. merchSn: '',
  51. openTicketAttr: false,
  52. ticketDiscountList: [],
  53. detailTicketDiscountList: [],
  54. discountSize: 9999, //查看全部
  55. discountDetailSize: 3, //详情查看部分
  56. campDetailSize: 1, //详情查看部分
  57. detailStoreCampMinusList: [],
  58. storeCampMinusList: []
  59. },
  60. onLoad: function(options) {
  61. // 页面初始化 options为页面跳转所带来的参数
  62. //由渠道推广生成的小程序码带来的参数,格式:商品id&门店id&推广id&用户id
  63. // options.scene = "1181115&20&1&26";
  64. // options.scene = "1181167&12&5&26";
  65. // options.scene = "1181133&12&6&26";
  66. // options.scene = "1181133&12&&26";
  67. var paramView = '';
  68. if (options.scene) {
  69. paramView = 'indexGoods';
  70. var scene = decodeURIComponent(options.scene);
  71. console.log("scene is ", scene);
  72. var scanArray = scene.split('&');
  73. var id = scanArray[0];
  74. var storeId = scanArray[1];
  75. var promId = scanArray[2];
  76. var referrer = scanArray[3];
  77. console.log("id is ", id);
  78. console.log("storeId is ", storeId);
  79. console.log("promId is ", promId);
  80. console.log("referrer is ", referrer);
  81. this.setData({
  82. id: id,
  83. storeId: storeId,
  84. promId: promId,
  85. referrer: referrer
  86. });
  87. if (storeId) {
  88. wx.setStorageSync('storeId', storeId);
  89. wx.setStorageSync('isShare', 'true'); //商品详情是由用户分享进入的
  90. }
  91. } else {
  92. //由列表页、与普通用户分享点进来带来的参数,商品id,门店id;商品id,门店id,分享用户
  93. this.setData({
  94. id: parseInt(options.id)
  95. });
  96. if (options.paramView){
  97. paramView = options.paramView;
  98. }
  99. if (options.storeId) {
  100. this.setData({
  101. storeId: options.storeId
  102. });
  103. wx.setStorageSync('storeId', options.storeId);
  104. }
  105. if (options.referrer) {
  106. this.setData({
  107. referrer: options.referrer
  108. });
  109. wx.setStorageSync('isShare', 'true');
  110. } else {
  111. wx.removeStorageSync('isShare'); //由列表页、与普通用户分享点进来则清除是否分享缓存
  112. }
  113. }
  114. var that = this;
  115. if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')){
  116. // 高度自适应
  117. wx.getSystemInfo({
  118. success: function (res) {
  119. var clientHeight = res.windowHeight,
  120. clientWidth = res.windowWidth,
  121. rpxR = 750 / clientWidth;
  122. var calc = clientHeight * rpxR - 100;
  123. // console.log(calc);
  124. that.setData({
  125. winHeight: calc,
  126. windowWidth: res.windowWidth
  127. });
  128. }
  129. });
  130. } else {
  131. // wx.navigateTo({
  132. // url: '/pages/auth/btnAuth/btnAuth',
  133. // })
  134. wx.navigateTo({
  135. url: '/pages/ucenter/userLogin/userLogin?view=' + paramView
  136. })
  137. }
  138. },
  139. onShow: function () {
  140. let that = this;
  141. // 页面显示
  142. if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) {
  143. if (wx.getStorageSync('storeId')) {
  144. // console.log('加载成功')
  145. util.request(api.ChooseStoreId, {
  146. storeId: wx.getStorageSync('storeId'),
  147. merchSn: wx.getStorageSync('merchSn'),
  148. isRefusedLogin: wx.getStorageSync('isRefusedLogin')
  149. }, 'POST').then(function (res) {
  150. if (res.errno === 0) {
  151. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  152. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  153. that.reLoad();
  154. that.getGoodsInfo();
  155. util.request(api.CartGoodsCount, {
  156. storeId: wx.getStorageSync('storeId')
  157. }).then(function (res) {
  158. if (res.errno === 0) {
  159. that.setData({
  160. cartGoodsCount: res.data.cartTotal.goodsCount
  161. });
  162. }
  163. });
  164. }
  165. });
  166. }
  167. }
  168. },
  169. onReady: function() {
  170. let that = this;
  171. this.videoContext = wx.createVideoContext('myVideo');
  172. // 页面渲染完成
  173. // wx.setClipboardData({
  174. // data: '/pages/goods/goods?id=' + that.data.id,
  175. // success: function (res) {
  176. // wx.getClipboardData({
  177. // success: function (res) {
  178. // // console.log(res.data) // data
  179. // }
  180. // })
  181. // }
  182. // })
  183. },
  184. toggleNav() {
  185. this.setData({
  186. showNavList: !this.data.showNavList
  187. })
  188. },
  189. switchNav(event) {
  190. let name = event.currentTarget.dataset.name;
  191. wx.switchTab({
  192. url: `/pages/${name}/${name}`,
  193. });
  194. },
  195. //小程序里的转义方法
  196. escape2Html: function(str) {
  197. var arrEntities = {
  198. 'lt': '<',
  199. 'gt': '>',
  200. 'nbsp': ' ',
  201. 'amp': '&',
  202. 'quot': '"'
  203. };
  204. return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function(all, t) {
  205. return arrEntities[t];
  206. });
  207. },
  208. //调用在需要的地方直接调用即可。如:this.escape2Html(contents)
  209. getGoodsInfo: function() {
  210. wx.showLoading({
  211. title: '加载中...',
  212. });
  213. setTimeout(function() {}, 350)
  214. let that = this;
  215. const regex = new RegExp('<img', 'gi');
  216. console.log('分享的storeId' + wx.getStorageSync('storeId'))
  217. // console.log('promId' + that.data.promId)
  218. util.request(api.GoodsDetail, {
  219. id: that.data.id,
  220. referrer: that.data.referrer,
  221. merchSn: wx.getStorageSync('merchSn'),
  222. storeId: wx.getStorageSync('storeId'),
  223. promId: that.data.promId
  224. }).then(function(res) {
  225. if (res.errno === 0) {
  226. that.setData({
  227. goods: res.data.info,
  228. gallery: res.data.gallery,
  229. attribute: res.data.attribute,
  230. issueList: res.data.issue,
  231. comment: res.data.comment,
  232. brand: res.data.brand,
  233. specificationList: res.data.specificationList,
  234. productList: res.data.productList,
  235. userHasCollect: res.data.userHasCollect,
  236. stockNum: res.data.stockNum,
  237. cartNumber: res.data.cartNumber,
  238. defaultFreight: res.data.defaultFreight,
  239. checkedSpecText: res.data.specificationList[0].valueList[0].value,
  240. detailContent: that.escape2Html(res.data.info.goods_desc).replace(regex, `<img style="width: 100%;"`),
  241. detailStoreId: res.data.info.storeId,
  242. merchSn: res.data.info.merchSn
  243. });
  244. that.getDetailTicketDiscountList();
  245. that.getDetailStoreCampMinusList();
  246. if (res.data.userHasCollect == 1) {
  247. that.setData({
  248. 'collectBackImage': that.data.hasCollectImage
  249. });
  250. } else {
  251. that.setData({
  252. 'collectBackImage': that.data.noCollectImage
  253. });
  254. }
  255. // WxParse.wxParse('goodsDetail', 'html', res.data.info.goods_desc, that);
  256. that.getGoodsRelated();
  257. // that.getGoodsCrashList();
  258. //
  259. let _specificationList = that.data.specificationList;
  260. for (let i = 0; i < _specificationList.length; i++) {
  261. if (_specificationList[i].valueList.length == 1) {
  262. //如果已经选中,则反选,前端默认选中
  263. _specificationList[i].valueList[0].checked = true;
  264. }
  265. }
  266. that.setData({
  267. 'specificationList': _specificationList
  268. });
  269. }
  270. wx.hideLoading();
  271. });
  272. if (null != that.data.referrer && that.data.referrer > 0) {
  273. //转发获取优惠券
  274. util.request(api.GoodsTransferCoupon, {
  275. goods_id: that.data.id,
  276. referrer: that.data.referrer,
  277. send_type: 2
  278. }).then(function(res) {
  279. });
  280. }
  281. //商品列表图
  282. util.request(api.GoodsGallery, {
  283. goods_id: that.data.id
  284. }).then(function(res) {
  285. if (res.errno === 0) {
  286. that.setData({
  287. gallery: res.data
  288. })
  289. }
  290. });
  291. },
  292. // getGoodsCrashList: function () {
  293. // let that = this;
  294. // util.request(api.GoodsCrashList, { goodsId: that.data.id }).then(function (res) {
  295. // if (res.errno === 0) {
  296. // that.setData({
  297. // crashList: res.data,
  298. // });
  299. // that.data.crashList.length;
  300. // }
  301. // });
  302. // },
  303. clickSkuValue: function(event) {
  304. let that = this;
  305. let specNameId = event.currentTarget.dataset.nameId;
  306. let specValueId = event.currentTarget.dataset.valueId;
  307. //
  308. let _specificationList = this.data.specificationList;
  309. for (let i = 0; i < _specificationList.length; i++) {
  310. if (_specificationList[i].specification_id == specNameId) {
  311. for (let j = 0; j < _specificationList[i].valueList.length; j++) {
  312. if (_specificationList[i].valueList[j].id == specValueId) {
  313. //如果已经选中,则反选
  314. if (_specificationList[i].valueList[j].checked) {
  315. _specificationList[i].valueList[j].checked = false;
  316. } else {
  317. _specificationList[i].valueList[j].checked = true;
  318. }
  319. } else {
  320. _specificationList[i].valueList[j].checked = false;
  321. }
  322. }
  323. }
  324. }
  325. this.setData({
  326. 'specificationList': _specificationList
  327. });
  328. //重新计算spec改变后的信息
  329. goodsUtil.changeSpecInfo(that);
  330. },
  331. //购物车增加
  332. addNumber2: function(e) {
  333. let that = this;
  334. var goodsId = e.currentTarget.dataset.goodsId;
  335. var productId = e.currentTarget.dataset.productId;
  336. var hotGoods = that.data.hotGoods;
  337. util.request(api.CartAdd, {
  338. goodsId: goodsId,
  339. productId: productId,
  340. number: 1
  341. }, 'POST').then(function(res) {
  342. if (res.errno === 0 && null != res.data) {
  343. util.request(api.CartGoodsCount, {
  344. storeId: wx.getStorageSync('storeId')
  345. }).then(function(res) {
  346. if (res.errno === 0) {
  347. that.setData({
  348. cartGoodsCount: res.data.cartTotal.goodsCount
  349. });
  350. }
  351. });
  352. wx.showToast({
  353. title: '添加成功',
  354. icon: 'success',
  355. mask: true
  356. });
  357. } else {
  358. wx.showToast({
  359. title: res.errmsg,
  360. icon: 'none'
  361. })
  362. }
  363. });
  364. },
  365. onHide: function() {
  366. // 页面隐藏
  367. },
  368. onUnload: function() {
  369. // 页面关闭
  370. },
  371. switchAttrPop: function() {
  372. this.setData({
  373. openAttr: !this.data.openAttr,
  374. openAttrByOrder: false,
  375. openTicketAttr: false,
  376. openCampMinusAttr: false
  377. })
  378. },
  379. hideSwitchAttrPop: function() {
  380. this.setData({
  381. openAttr: false,
  382. openAttrByOrder: false,
  383. openTicketAttr: false,
  384. openCampMinusAttr: false
  385. })
  386. },
  387. switchAttrPopByOrder: function () {
  388. this.setData({
  389. openAttr: false,
  390. openAttrByOrder: !this.data.openAttrByOrder,
  391. openTicketAttr: false,
  392. openCampMinusAttr: false
  393. })
  394. },
  395. reLoad: function() {
  396. let that = this;
  397. if (wx.getStorageSync('storeId')) {
  398. if (wx.getStorageSync('userId')) {
  399. wx.request({
  400. url: api.updateLoginUser,
  401. data: {
  402. userId: wx.getStorageSync('userId'),
  403. storeId: wx.getStorageSync('storeId'),
  404. merchSn: wx.getStorageSync('merchSn')
  405. },
  406. method: 'POST',
  407. header: {
  408. 'Content-Type': 'application/json'
  409. },
  410. success: function(wxRes) {
  411. if (wxRes.data.errno === 0) {
  412. // console.log("用户信息更新成功");
  413. }
  414. },
  415. fail: function(err) {
  416. console.log("failed");
  417. }
  418. });
  419. }
  420. }
  421. },
  422. changeProperty: function(e) {
  423. var propertyName = e.currentTarget.dataset.propertyName;
  424. console.log(propertyName);
  425. },
  426. closeAttrOrCollect: function() {
  427. let that = this;
  428. //添加或是取消收藏
  429. util.request(api.CollectAddOrDelete, {
  430. typeId: 0,
  431. valueId: this.data.id
  432. }, "POST")
  433. .then(function(res) {
  434. let _res = res;
  435. if (_res.errno == 0) {
  436. if (_res.data.type == 'add') {
  437. that.setData({
  438. 'collectBackImage': that.data.hasCollectImage
  439. });
  440. wx.showToast({
  441. title: "收藏成功",
  442. mask: true
  443. });
  444. } else {
  445. that.setData({
  446. 'collectBackImage': that.data.noCollectImage
  447. });
  448. wx.showToast({
  449. title: "收藏取消",
  450. mask: true
  451. });
  452. }
  453. } else {
  454. wx.showToast({
  455. image: '/static/images/icon_error.png',
  456. title: _res.errmsg,
  457. mask: true
  458. });
  459. }
  460. });
  461. },
  462. openCartPage: function() {
  463. wx.switchTab({
  464. url: '/pages/cart/cart',
  465. });
  466. },
  467. addToCart: function() {
  468. var that = this;
  469. if (this.data.openAttr == false) {
  470. //打开规格选择窗口
  471. this.setData({
  472. openAttr: !this.data.openAttr,
  473. openAttrByOrder: false,
  474. number: 1
  475. });
  476. } else {
  477. //提示选择完整规格
  478. if (!goodsUtil.isCheckedAllSpec(that)) {
  479. return false;
  480. }
  481. if (that.data.number + that.data.cartNumber > that.data.stockNum) {
  482. // wx.showToast({
  483. // title: '库存不足',
  484. // mask: true
  485. // });
  486. if (that.data.cartNumber == that.data.stockNum){
  487. wx.showToast({
  488. title: '不能再加了,购物车中已加入库存' + that.data.cartNumber + '个',
  489. icon: 'none'
  490. })
  491. }else{
  492. util.showErrorToast('库存不足');
  493. }
  494. // util.showErrorToast('库存不足');
  495. //找不到对应的product信息,提示没有库存
  496. return false;
  497. }
  498. // console.log(that.data.productList)
  499. // //根据选中的规格,判断是否有对应的sku信息
  500. let checkedProduct = goodsUtil.getCheckedProductItem(goodsUtil.getCheckedSpecKey(that), that);
  501. // console.log(goodsUtil.getCheckedSpecKey(that))
  502. if (!checkedProduct || checkedProduct.length <= 0) {
  503. wx.showToast({
  504. title: '库存不足',
  505. icon: 'none'
  506. });
  507. //找不到对应的product信息,提示没有库存
  508. return false;
  509. }
  510. //验证库存
  511. // if (checkedProduct.goods_number < this.data.number) {
  512. // //找不到对应的product信息,提示没有库存
  513. // return false;
  514. // }
  515. //添加到购物车
  516. util.request(api.CartAdd, {
  517. goodsId: this.data.goods.id,
  518. number: this.data.number,
  519. productId: checkedProduct[0].id,
  520. promId: that.data.promId
  521. }, "POST")
  522. .then(function(res) {
  523. let _res = res;
  524. if (_res.errno == 0) {
  525. wx.showToast({
  526. title: '添加成功'
  527. });
  528. that.setData({
  529. openAttr: !that.data.openAttr,
  530. openAttrByOrder: false,
  531. cartGoodsCount: _res.data.cartTotal.goodsCount
  532. });
  533. if (that.data.userHasCollect == 1) {
  534. that.setData({
  535. 'collectBackImage': that.data.hasCollectImage
  536. });
  537. } else {
  538. that.setData({
  539. 'collectBackImage': that.data.noCollectImage
  540. });
  541. }
  542. } else {
  543. wx.showToast({
  544. title: _res.errmsg,
  545. icon: 'none'
  546. })
  547. that.hideSwitchAttrPop();
  548. // that.setData({
  549. // stockNum: 0
  550. // });
  551. }
  552. });
  553. }
  554. },
  555. cutNumber: function() {
  556. this.setData({
  557. number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
  558. });
  559. },
  560. addNumber: function() {
  561. this.setData({
  562. number: this.data.number + 1
  563. });
  564. },
  565. onShareAppMessage: function() {
  566. var that = this;
  567. // console.log("url:" + that.data.goods.list_pic_url);
  568. var userId = wx.getStorageSync('userId');
  569. console.log("userId:" + userId);
  570. console.log("detailStoreId:" + that.data.detailStoreId);
  571. console.log("merchSn:" + that.data.merchSn);
  572. console.log("promId:" + that.data.promId);
  573. var requestUrl = "";
  574. if (that.data.promId) {
  575. requestUrl = '/pages/goods/goods?scene=' + that.data.id + '&' + that.data.detailStoreId + '&' + that.data.promId +
  576. '&' + wx.getStorageSync('userId');
  577. } else {
  578. requestUrl = '/pages/goods/goods?id=' + that.data.id + '&&referrer=' + wx.getStorageSync('userId') +
  579. '&&storeId=' + that.data.detailStoreId +
  580. '&&merchSn=' + that.data.merchSn;
  581. }
  582. // console.log("requestUrl:" + requestUrl);
  583. return {
  584. title: '商品详情',
  585. desc: null != that.data.goods.name ? that.data.goods.name : "商品详情",
  586. imageUrl: that.data.goods.list_pic_url,
  587. path: requestUrl,
  588. success: function(res) {
  589. // console.log("转发成功");
  590. console.log("转发成功12:" + that.data.promId);
  591. if (that.data.promId) {
  592. //转发成功记录推广信息转发次数
  593. wx.request({
  594. url: api.GoodsSaveTransNum,
  595. data: {
  596. referrer: wx.getStorageSync('userId'),
  597. storeId: that.data.detailStoreId,
  598. promId: that.data.promId
  599. },
  600. method: 'POST',
  601. header: {
  602. 'Content-Type': 'application/json'
  603. },
  604. success: function(wxRes) {
  605. console.log("转发成功");
  606. }
  607. });
  608. }
  609. },
  610. fail: function(res) {
  611. console.log("转发失败");
  612. }
  613. }
  614. },
  615. //购物车增加
  616. addCrashNumber: function(e) {
  617. let that = this;
  618. var goodsId = e.currentTarget.dataset.goodsId;
  619. var productId = e.currentTarget.dataset.productId;
  620. util.request(api.CartAdd, {
  621. goodsId: goodsId,
  622. productId: productId,
  623. number: 1
  624. }, 'POST').then(function(res) {
  625. if (res.errno === 0 && null != res.data) {
  626. var hotGoods = that.data.hotGoods;
  627. hotGoods.forEach(function(val, index, arr) {
  628. if (val.id == goodsId) {
  629. val.cart_num = res.data;
  630. hotGoods[index] = val;
  631. that.setData({
  632. hotGoods: hotGoods
  633. });
  634. }
  635. }, that);
  636. }
  637. });
  638. },
  639. previewPic(e) {
  640. let url = e.currentTarget.dataset.url;
  641. let urls = [];
  642. urls[0] = url;
  643. wx.previewImage({
  644. urls
  645. })
  646. },
  647. switchNav(event) {
  648. wx.switchTab({
  649. url: '/pages/index/index'
  650. });
  651. },
  652. //触摸事件start
  653. touchStart(e) {
  654. let startX = e.changedTouches[0].pageX
  655. this.setData({
  656. startX: startX
  657. })
  658. console.log("startX:" + startX);
  659. },
  660. //触摸事件end
  661. touchEnd(e) {
  662. let _self = this;
  663. let windowWidth = this.data.windowWidth;
  664. let moveWidth = e.changedTouches[0].pageX - this.data.startX;
  665. let defineWidth = windowWidth / 20;
  666. let rankList = this.data.gallery;
  667. let index_now = e.currentTarget.dataset.index;
  668. if (moveWidth >= defineWidth) {
  669. //上一张
  670. let transWidth = (index_now - 1) * (-this.data.windowWidth);
  671. if (index_now >= 1) {
  672. this.setData({
  673. indexNum: index_now - 1,
  674. rankList: rankList,
  675. leftWidth: transWidth
  676. })
  677. }
  678. } else if (moveWidth <= (0 - defineWidth)) {
  679. //下一张
  680. this.videoContext.pause();
  681. let transWidth = (index_now + 1) * (-this.data.windowWidth);
  682. if (index_now < rankList.length - 1) {
  683. this.setData({
  684. indexNum: index_now + 1,
  685. rankList: rankList,
  686. leftWidth: transWidth
  687. })
  688. }
  689. } else {
  690. //console.log('不能修改样式')
  691. }
  692. },
  693. videoPlay(e) {
  694. // if (this.data.curr_id == e.currentTarget.dataset.id) {
  695. // this.setData({
  696. // curr_id: 0,
  697. // })
  698. // } else {
  699. // this.setData({
  700. // curr_id: e.currentTarget.dataset.id,
  701. // })
  702. // }
  703. this.setData({
  704. imgHiddenName: true,
  705. videoHiddenName: false
  706. })
  707. this.videoContext.play();
  708. },
  709. //触摸事件start
  710. touchStart2(e) {
  711. },
  712. touchEnd2(e) {
  713. this.setData({
  714. curr_id: 0,
  715. imgHiddenName: false,
  716. videoHiddenName: true
  717. })
  718. this.videoContext.pause();
  719. },
  720. getGoodsRelated: function() {
  721. let that = this;
  722. util.request(api.GoodsRelated, {
  723. id: that.data.id,
  724. page: that.data.page,
  725. size: that.data.size
  726. }).then(function(res) {
  727. if (res.errno === 0) {
  728. let goodsList = that.data.relatedGoods.concat(res.data.goodsList);
  729. that.setData({
  730. relatedGoods: goodsList,
  731. });
  732. }
  733. });
  734. },
  735. onReachBottom() {
  736. var that = this;
  737. wx.showLoading({
  738. title: '加载中...',
  739. })
  740. that.setData({
  741. page: that.data.page + 1
  742. });
  743. that.getGoodsRelated();
  744. },
  745. switchTicketPop: function() {
  746. this.setData({
  747. openTicketAttr: !this.data.openTicketAttr,
  748. openAttr: false,
  749. openAttrByOrder: false,
  750. openCampMinusAttr: false
  751. })
  752. if (this.data.openTicketAttr) {
  753. this.getTicketDiscountList();
  754. }
  755. },
  756. // hideSwitchTicketPop: function () {
  757. // this.setData({
  758. // openTicketAttr: false,
  759. // openAttr: false
  760. // })
  761. // },
  762. /**
  763. * 领取优惠券
  764. */
  765. getUserCoupon(event) {
  766. var that = this;
  767. let tickDiscId = event.currentTarget.dataset.couponId;
  768. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  769. let storeId = that.data.storeId;
  770. util.request(api.getUserCoupon, {
  771. tickDiscId: tickDiscId,
  772. storeTopicId: storeTopicId,
  773. storeId: storeId
  774. }, 'POST').then(function(res) {
  775. if (res.errno === 0) {
  776. wx.showToast({
  777. title: '领取成功'
  778. });
  779. that.setData({
  780. discStatus: 0
  781. });
  782. that.getTicketDiscountList();
  783. } else {
  784. wx.showToast({
  785. title: res.errmsg,
  786. icon: 'none'
  787. })
  788. }
  789. });
  790. },
  791. /**
  792. * 查看优惠券列表
  793. */
  794. getTicketDiscountList() {
  795. let that = this;
  796. util.request(api.DiscountByGoodsIdList, {
  797. storeId: that.data.storeId,
  798. goodsId: that.data.id,
  799. size: that.data.discountSize
  800. }).then(function(res) {
  801. if (res.errno === 0) {
  802. that.setData({
  803. ticketDiscountList: res.data
  804. });
  805. }
  806. });
  807. },
  808. /**
  809. * 查看优惠券列表,详情页展示
  810. */
  811. getDetailTicketDiscountList() {
  812. let that = this;
  813. util.request(api.DiscountByGoodsIdList, {
  814. storeId: that.data.storeId,
  815. goodsId: that.data.id,
  816. size: that.data.discountDetailSize
  817. }).then(function(res) {
  818. if (res.errno === 0) {
  819. that.setData({
  820. detailTicketDiscountList: res.data
  821. });
  822. }
  823. });
  824. },
  825. /**
  826. * 查看满减满折列表
  827. */
  828. getStoreCampMinusList() {
  829. let that = this;
  830. util.request(api.StoreCampMinusByGoodsIdList, {
  831. storeId: that.data.storeId,
  832. goodsId: that.data.id,
  833. size: that.data.discountSize
  834. }).then(function(res) {
  835. if (res.errno === 0) {
  836. that.setData({
  837. storeCampMinusList: res.data
  838. });
  839. let storeCampMinusList = that.data.storeCampMinusList
  840. for (let i = 0; i < storeCampMinusList.length; i++) {
  841. if (storeCampMinusList[i].campMinusType == '00' && storeCampMinusList[i].minusMode == '00') {
  842. that.setData({
  843. minusList0000: true
  844. });
  845. }
  846. if (storeCampMinusList[i].campMinusType == '01' && storeCampMinusList[i].minusMode == '00') {
  847. that.setData({
  848. minusList0100: true
  849. });
  850. }
  851. if (storeCampMinusList[i].campMinusType == '00' && storeCampMinusList[i].minusMode == '10') {
  852. that.setData({
  853. minusList0010: true
  854. });
  855. }
  856. if (storeCampMinusList[i].campMinusType == '01' && storeCampMinusList[i].minusMode == '10') {
  857. that.setData({
  858. minusList0110: true
  859. });
  860. }
  861. if (storeCampMinusList[i].campMinusType == '10') {
  862. that.setData({
  863. minusList10: true
  864. });
  865. }
  866. if (storeCampMinusList[i].campMinusType == '11') {
  867. that.setData({
  868. minusList11: true
  869. });
  870. }
  871. }
  872. }
  873. });
  874. },
  875. /**
  876. * 查看满减满折列表,详情页展示
  877. */
  878. getDetailStoreCampMinusList() {
  879. let that = this;
  880. util.request(api.StoreCampMinusByGoodsIdList, {
  881. storeId: that.data.storeId,
  882. goodsId: that.data.id,
  883. size: that.data.campDetailSize
  884. }).then(function(res) {
  885. if (res.errno === 0) {
  886. that.setData({
  887. detailStoreCampMinusList: res.data
  888. });
  889. }
  890. });
  891. },
  892. switchCampMinusPop: function() {
  893. this.setData({
  894. openCampMinusAttr: !this.data.openCampMinusAttr,
  895. openTicketAttr: false,
  896. openAttrByOrder: false,
  897. openAttr: false
  898. })
  899. if (this.data.openCampMinusAttr) {
  900. this.getStoreCampMinusList();
  901. }
  902. },
  903. hideSwitchCampMinusPop: function() {
  904. this.setData({
  905. openCampMinusAttr: false,
  906. openTicketAttr: false,
  907. openAttrByOrder: false,
  908. openAttr: false
  909. })
  910. },
  911. selectCampMinus(event) {
  912. var that = this;
  913. let campId = event.currentTarget.dataset.campId;
  914. let campName = event.currentTarget.dataset.campName;
  915. wx.navigateTo({
  916. url: '../ucenter/campMinus/campMinus?campMinusId=' + campId + '&&storeId=' + that.data.storeId + '&&campName=' + campName + "&&isShare=1"
  917. })
  918. },
  919. checkoutOrder: function() {
  920. //获取已选择的商品
  921. let that = this;
  922. util.request(api.getCurUser, {
  923. userInfo: app.globalData.userInfo
  924. }, 'POST').then(function(res) {
  925. if (res.errno === 0) {
  926. // console.log('that.data.mobile:' + res.data.mobile);
  927. if (res.data.mobile == '' || res.data.mobile == null) {
  928. wx.showModal({
  929. title: '',
  930. confirmColor: '#b4282d',
  931. showCancel: false,
  932. content: '您的手机号码未绑定,请先绑定手机号再进行购买',
  933. success: function(res) {
  934. if (res.confirm) {
  935. wx.navigateTo({
  936. url: '../../pages/auth/newuser/newuser'
  937. });
  938. }
  939. }
  940. });
  941. } else {
  942. if (that.data.openAttrByOrder == false) {
  943. //打开规格选择窗口
  944. that.setData({
  945. openAttrByOrder: !that.data.openAttrByOrder,
  946. openAttr: false,
  947. number: 1
  948. });
  949. } else {
  950. //提示选择完整规格
  951. if (!goodsUtil.isCheckedAllSpec(that)) {
  952. return false;
  953. }
  954. if (that.data.number > that.data.stockNum) {
  955. util.showErrorToast('库存不足');
  956. return false;
  957. }
  958. // //根据选中的规格,判断是否有对应的sku信息
  959. let checkedProduct = goodsUtil.getCheckedProductItem(goodsUtil.getCheckedSpecKey(that), that);
  960. //找不到对应的product信息,提示没有库存
  961. if (!checkedProduct || checkedProduct.length <= 0) {
  962. wx.showToast({
  963. title: '库存不足',
  964. icon: 'none'
  965. });
  966. return false;
  967. }
  968. wx.navigateTo({
  969. url: '../shopping/checkout/checkout?checkCart=00&&goodsId=' + that.data.id + '&&number=' + that.data.number
  970. })
  971. }
  972. }
  973. }
  974. });
  975. },
  976. })