1
0

goods.js 28 KB

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