1
0

index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. const util = require('../../utils/util.js');
  2. const api = require('../../config/api.js');
  3. const user = require('../../services/user.js');
  4. //获取应用实例
  5. const app = getApp();
  6. Page({
  7. data: {
  8. groupGoods: [],
  9. hotGoods: [],
  10. topics: [],
  11. brands: [],
  12. floorGoods: [],
  13. banner: [],
  14. channel: [],
  15. groupBanner: {},
  16. storeName: '',
  17. showPop: false, //活动弹窗
  18. couponVo: {},
  19. storeId: '',
  20. page: 1,
  21. size: 3,
  22. list: [],
  23. openAttr: false,
  24. isMapShow: '', //第三方商户是否启用地图显示
  25. isStartLocation: null,
  26. isSystemLocation: null
  27. },
  28. onLoad: function(options) {
  29. let that = this;
  30. wx.setStorageSync("navUrl", "/pages/index/index");
  31. // options.scene = 148;
  32. // options.scene = 93;
  33. // options.scene = 38;
  34. // options.scene = 67;
  35. // options.scene = 28;
  36. // options.scene = 8;
  37. if (options.scene) {
  38. // console.log("have scene");
  39. var scene = decodeURIComponent(options.scene);
  40. console.log("scene is ", scene);
  41. that.setData({
  42. storeId: scene
  43. });
  44. wx.setStorageSync('storeId', scene);
  45. //扫码进入的小程序则清除是否分享缓存
  46. wx.removeStorageSync('isShare');
  47. } else {
  48. //是否分享过商品,有数据则分享过;从首页进入页面则没有分享过,从详情页进入则分享过
  49. if (wx.getStorageSync('isShare') == 'true') {
  50. console.log('是分享进入首页门店id:' + wx.getStorageSync('storeId') + ',从商品页获取的缓存')
  51. console.log('是分享进入首页:' + wx.getStorageSync('isShare'))
  52. } else {
  53. //小程序入口进入的主页,则清除storeId,获取当前地址最近的门店
  54. wx.removeStorageSync('storeId');
  55. // console.log('不是分享进入首页门店id:【' + wx.getStorageSync('storeId') + '】,获取最近门店')
  56. // console.log('不是分享进入首页:' + wx.getStorageSync('isShare'))
  57. }
  58. }
  59. wx.getLocation({
  60. success: function(location) {
  61. // that.successLoadStore(location);
  62. },
  63. fail: function() {
  64. wx.hideLoading();
  65. wx.getSetting({
  66. success: function(res) {
  67. if (!res.authSetting['scope.userLocation']) {
  68. wx.showModal({
  69. title: '',
  70. content: '检测到您没有开启获取地理位置权限,是否开启',
  71. confirmText: '确定',
  72. success: function(resConfirm) {
  73. if (resConfirm.confirm) {
  74. wx.openSetting();
  75. } else {
  76. that.setData({
  77. isStartLocation: false
  78. });
  79. }
  80. }
  81. })
  82. } else {
  83. //用户已授权,但是获取地理位置失败,提示用户去系统设置中打开定位
  84. wx.showModal({
  85. title: '',
  86. content: '请在系统设置中打开定位服务',
  87. confirmText: '确定',
  88. showCancel: false,
  89. success: function(resConfirm2) {
  90. that.setData({
  91. isSystemLocation: false
  92. });
  93. }
  94. })
  95. }
  96. }
  97. })
  98. }
  99. });
  100. },
  101. onReady: function() {
  102. // 页面渲染完成
  103. },
  104. onShow: function() {
  105. // 页面显示
  106. let that = this;
  107. wx.setStorageSync("navUrl", "/pages/index/index");
  108. wx.setStorageSync("isLocationIndex", "false"); //购物车是否已跳转登录页,到首页重置字段为false未跳转
  109. if (!wx.getStorageSync('isRefusedLogin')) {
  110. if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) {
  111. console.log('缓存是否授权为空,用户已授权:' + wx.getStorageSync('isRefusedLogin'))
  112. wx.setStorageSync('isRefusedLogin', 'false');
  113. } else {
  114. console.log('缓存是否授权为空,用户未授权:' + wx.getStorageSync('isRefusedLogin'))
  115. wx.setStorageSync('isRefusedLogin', 'true'); //拒绝授权
  116. }
  117. } else {
  118. console.log('授权不为空:' + wx.getStorageSync('isRefusedLogin'))
  119. wx.setStorageSync('isRefusedLogin', 'false');
  120. }
  121. that.syncStore();
  122. // if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) {
  123. // } else {
  124. // // console.log('拒绝授权:' + wx.getStorageSync('isRefusedLogin'))
  125. // if (wx.getStorageSync('isRefusedLogin') != 'true') {
  126. // wx.navigateTo({
  127. // url: '/pages/auth/btnAuth/btnAuth',
  128. // })
  129. // }
  130. // }
  131. },
  132. onHide: function() {
  133. // 页面隐藏
  134. },
  135. onUnload: function() {
  136. // 页面关闭
  137. },
  138. showCouponPop() {
  139. let that = this;
  140. this.setData({
  141. showPop: false
  142. });
  143. // wx.showToast({
  144. // title: '恭喜获取优惠券一张' + that.data.couponVo.name,
  145. // duration: 2000
  146. // });
  147. wx.showModal({
  148. title: '获取优惠券一张',
  149. showCancel: false,
  150. content: that.data.couponVo.name
  151. })
  152. },
  153. onShareAppMessage: function() {
  154. var that = this;
  155. // console.log('分享:' + that.data.storeId)
  156. return {
  157. title: '中网跨境电商主页',
  158. desc: '中网跨境电商主页',
  159. path: '/pages/index/index?scene=' + that.data.storeId
  160. }
  161. },
  162. // 同步门店
  163. syncStore: function() {
  164. let that = this;
  165. // console.log(wx.getStorageSync('merchSn'));
  166. //获取附件门店信息
  167. // util.getLocation((lng, lat) => {
  168. wx.getLocation({
  169. success: function(location) {
  170. // console.log(location)
  171. that.successLoadStore(location);
  172. },
  173. fail: function() {
  174. wx.hideLoading();
  175. wx.getSetting({
  176. success: function(res) {
  177. if (!res.authSetting['scope.userLocation']) {
  178. that.setData({
  179. isStartLocation: false
  180. });
  181. } else {
  182. //用户已授权,但是获取地理位置失败,提示用户去系统设置中打开定位
  183. that.setData({
  184. isSystemLocation: false
  185. });
  186. // wx.showModal({
  187. // title: '',
  188. // content: '请在系统设置中打开定位服务',
  189. // confirmText: '确定',
  190. // showCancel: false,
  191. // success: function (resConfirm2) {
  192. // that.setData({
  193. // isSystemLocation: false
  194. // });
  195. // }
  196. // })
  197. }
  198. }
  199. });
  200. }
  201. });
  202. },
  203. /**
  204. * 打开微信定位
  205. */
  206. openSetLocation: function() {
  207. wx.openSetting();
  208. },
  209. /**confirmLocation: function () {
  210. let that = this;
  211. wx.showModal({
  212. title: '',
  213. content: '检测到您没有开启获取地理位置权限,是否开启',
  214. confirmText: '确定',
  215. success: function (resConfirm) {
  216. if (resConfirm.confirm) {
  217. wx.openSetting();
  218. } else {
  219. that.confirmLocation();
  220. }
  221. }
  222. })
  223. },**/
  224. /**
  225. * 定位确定授权加载附近门店信息
  226. */
  227. successLoadStore: function(location) {
  228. let that = this;
  229. that.setData({
  230. isStartLocation: true,
  231. isSystemLocation: true
  232. });
  233. var lng = location.longitude;
  234. var lat = location.latitude;
  235. wx.setStorageSync('location', JSON.stringify({
  236. lng,
  237. lat
  238. }));
  239. let storeId = wx.getStorageSync('storeId');
  240. util.request(api.NearbyList, {
  241. longitude: lng,
  242. latitude: lat,
  243. storeId: storeId,
  244. thirdPartyMerchCode: ''
  245. }).then((res) => {
  246. let nlist = res.data;
  247. // wx.removeStorageSync('nearStoreList');
  248. // wx.removeStorageSync('storeId');
  249. // wx.removeStorageSync('storeVo');
  250. // wx.setStorageSync('storeId', storeId);
  251. if (!wx.getStorageSync('currentCategory')) {
  252. wx.removeStorageSync('currentCategory');
  253. }
  254. if (!nlist.length) {
  255. wx.removeStorageSync('nearStoreList');
  256. wx.removeStorageSync('mapIndexStoreId');
  257. } else {
  258. wx.setStorageSync('nearStoreList', JSON.stringify(nlist));
  259. wx.setStorageSync('mapIndexStoreId', nlist[0].id);
  260. }
  261. if (!nlist.length) {
  262. // wx.removeStorageSync('storeId');
  263. wx.removeStorageSync('storeVo');
  264. that.setData({
  265. storeName: '附近暂无门店'
  266. })
  267. } else {
  268. that.setData({
  269. storeName: nlist[0].storeName,
  270. storeId: nlist[0].id
  271. })
  272. that.checkLoginTokenByUpd(nlist);
  273. wx.setStorageSync('storeVo', JSON.stringify(nlist[0]));
  274. }
  275. })
  276. },
  277. /**
  278. * 校验token是否失效,失效则更新新token
  279. */
  280. checkLoginTokenByUpd: function (nlist){
  281. var that = this;
  282. util.request(api.checkToken, {
  283. token: wx.getStorageSync('token')
  284. }, 'POST').then(function (res) {
  285. if (res.data.errno == 401) {
  286. console.log(res.data.errmsg)
  287. wx.login({
  288. success: function (loginRes) {
  289. if (loginRes.code) {
  290. //登录远程服务器
  291. wx.request({
  292. url: api.AuthLoginSaveToken,
  293. data: {
  294. code: loginRes.code,
  295. userInfo: wx.getStorageSync('userInfo'),
  296. storeId: that.data.storeId,
  297. merchSn: nlist[0].merchSn
  298. },
  299. method: 'POST',
  300. header: {
  301. 'Content-Type': 'application/json'
  302. },
  303. success: function (wxRes) {
  304. // console.log(wxRes)
  305. if (wxRes.data.errno === 0) {
  306. //存储用户信息
  307. wx.setStorageSync('userInfo', wxRes.data.data.userInfo);
  308. wx.setStorageSync('token', wxRes.data.data.token);
  309. wx.setStorageSync('userId', wxRes.data.data.userId);
  310. wx.setStorageSync('isRefusedLogin', 'false');//允许授权
  311. console.log("登录成功");
  312. that.chooseStore(nlist[0].id, nlist[0].merchSn);
  313. }
  314. },
  315. fail: function (err) {
  316. console.log("failed");
  317. }
  318. });
  319. } else {
  320. console.log("failed");
  321. }
  322. },
  323. fail: function (err) {
  324. console.log("failed");
  325. }
  326. });
  327. } else {
  328. console.log('token未失效');
  329. // console.log(res)
  330. that.chooseStore(nlist[0].id, nlist[0].merchSn);
  331. }
  332. });
  333. },
  334. // 更新门店Id
  335. chooseStore: function(storeId, merchSn) {
  336. let that = this;
  337. util.request(api.ChooseStoreId, {
  338. storeId: storeId,
  339. merchSn: merchSn,
  340. isRefusedLogin: wx.getStorageSync('isRefusedLogin')
  341. }, 'POST').then(function (res) {
  342. if (res.errno === 0) {
  343. wx.setStorageSync('storeId', storeId);
  344. wx.setStorageSync('merchSn', merchSn);
  345. wx.setStorageSync('token', res.data.token);
  346. if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) {
  347. that.reLoad();
  348. } else {
  349. wx.setStorageSync('isLoadGoods', '0'); //1:代表每次点首页都会重新加载商品,0:否
  350. }
  351. that.getIndexData();
  352. that.enableActivity();
  353. that.getGroupData();
  354. }
  355. });
  356. },
  357. reLoad: function() {
  358. let that = this;
  359. // console.log(wx.getStorageSync('userId'));
  360. // console.log(wx.getStorageSync('storeId'));
  361. // console.log(wx.getStorageSync('merchSn'));
  362. if (wx.getStorageSync('storeId')) {
  363. if (wx.getStorageSync('userId')) {
  364. wx.request({
  365. url: api.updateLoginUser,
  366. data: {
  367. userId: wx.getStorageSync('userId'),
  368. storeId: wx.getStorageSync('storeId'),
  369. merchSn: wx.getStorageSync('merchSn')
  370. },
  371. method: 'POST',
  372. header: {
  373. 'Content-Type': 'application/json'
  374. },
  375. success: function(wxRes) {
  376. if (wxRes.data.errno === 0) {
  377. that.setData({
  378. isMapShow: wxRes.data.data.isMapShow
  379. });
  380. // console.log(wxRes.data.data.isLoadGoods);
  381. wx.setStorageSync('isLoadGoods', wxRes.data.data.isLoadGoods);
  382. wx.setStorageSync('thirdPartyMerchCode', wxRes.data.data.thirdPartyMerchCode);
  383. // console.log(that.data.isMapShow)
  384. // console.log("用户信息更新成功");
  385. }
  386. },
  387. fail: function(err) {
  388. console.log("failed");
  389. }
  390. });
  391. }
  392. }
  393. },
  394. getIndexData: function() {
  395. setTimeout(function() {}, 350)
  396. wx.showLoading({
  397. title: '加载中...',
  398. })
  399. let that = this;
  400. util.request(api.IndexUrl).then(function(res) {
  401. if (res.errno === 0) {
  402. // console.log(res.data.banner);
  403. that.setData({
  404. // newGoods: res.data.newGoodsList,
  405. // hotGoods: res.data.hotGoodsList,
  406. // topics: res.data.topicList,
  407. // brand: res.data.brandList,
  408. // floorGoods: res.data.categoryList,
  409. banner: res.data.banner,
  410. // groupBanner: res.data.groupBanner,
  411. channel: res.data.channel
  412. });
  413. // console.log(that.data.hotGoods.length)
  414. // console.log(wx.getStorageSync('storeId'))
  415. // console.log(wx.getStorageSync('mapIndexStoreId'))
  416. // if (that.data.hotGoods.length == 0) {
  417. // that.getGoodsList();
  418. // }
  419. // console.log("mapIndexStoreId:" + wx.getStorageSync('mapIndexStoreId'))
  420. // console.log("storeId:" + wx.getStorageSync('storeId'))
  421. // console.log("isShare:" + wx.getStorageSync('isShare'))
  422. // console.log("isLoadGoods:" + wx.getStorageSync('isLoadGoods'))
  423. //当切换了门店地图(mapIndexStoreId),或是由用户分享进入的商品详情切换进入的首页(isShare:true)
  424. if (wx.getStorageSync('storeId') != wx.getStorageSync('mapIndexStoreId') || wx.getStorageSync('isShare') == 'true' || that.data.hotGoods.length == 0 || wx.getStorageSync('isLoadGoods') == '1') {
  425. that.setData({
  426. hotGoods: [],
  427. page: 1
  428. });
  429. that.getGoodsList();
  430. if (wx.getStorageSync('isLoadGoods') == '1') {
  431. util.request(api.UpdateStoreLoadGoods, {
  432. storeId: wx.getStorageSync('storeId')
  433. }).then(function(res) {});
  434. }
  435. wx.setStorageSync('isShare', 'false');
  436. }
  437. }
  438. wx.hideLoading();
  439. });
  440. },
  441. getGoodsList: function() {
  442. let that = this;
  443. util.request(api.GoodsHot).then(function(res) {
  444. if (res.errno == 0) {
  445. util.request(api.HotGoodsList, {
  446. isHot: 1,
  447. page: that.data.page,
  448. size: that.data.size,
  449. categoryId: 0
  450. })
  451. .then(function(res) {
  452. if (res.errno == 0) {
  453. let goodsList = that.data.hotGoods.concat(res.data.goodsList);
  454. that.setData({
  455. hotGoods: goodsList,
  456. list: res.data.goodsList
  457. });
  458. }
  459. });
  460. wx.hideLoading();
  461. }
  462. });
  463. },
  464. getGroupData: function() {
  465. let that = this;
  466. util.request(api.GroupList).then(function(res) {
  467. if (res.errno === 0) {
  468. that.setData({
  469. groupGoods: res.data.data,
  470. });
  471. }
  472. });
  473. },
  474. handleStore() {
  475. wx.navigateTo({
  476. url: '../map/map',
  477. })
  478. },
  479. goSearch() {
  480. wx.navigateTo({
  481. url: '../search/search',
  482. })
  483. },
  484. goCatalog: function(e) {
  485. let url = '';
  486. // console.log('dataset.goodsBizType:' + e.currentTarget.dataset.goodsBizType);
  487. app.globalData.appGoodsBizType = e.currentTarget.dataset.goodsBizType;
  488. // console.log('appgoodsBizType1:' + app.globalData.appGoodsBizType);
  489. wx.setStorageSync('isSwitchCatalog', 'true'); //主页跳转至分类页加载商品,
  490. wx.switchTab({
  491. url: '/pages/catalog/catalog',
  492. });
  493. },
  494. onReachBottom: function() {
  495. if (this.data.bottomLoadDone === true || this.data.bottomLoading === true) {
  496. return false;
  497. }
  498. this.setData({
  499. bottomLoading: true
  500. });
  501. // this.getFloorCategory();
  502. },
  503. //购物车减少
  504. cutNumber: function(e) {
  505. let that = this;
  506. var goodsId = e.currentTarget.dataset.goodsId;
  507. var productId = e.currentTarget.dataset.productId;
  508. var hotGoods = that.data.hotGoods;
  509. // hotGoods.forEach(function (val, index, arr) {
  510. // if (val.product_id == productId) {
  511. // val.cart_num = val.cart_num - 1;
  512. // if (val.cart_num >= 0) {
  513. // hotGoods[index] = val;
  514. // }
  515. // }
  516. // });
  517. // that.setData({ hotGoods: hotGoods });
  518. util.request(api.CartMinus, {
  519. goodsId: goodsId,
  520. productId: productId,
  521. number: 1
  522. }, 'POST').then(function(res) {
  523. if (res.errno === 0 && null != res.data) {
  524. var hotGoods = that.data.hotGoods;
  525. hotGoods.forEach(function(val, index, arr) {
  526. if (val.product_id == productId) {
  527. val.cart_num = res.data;
  528. hotGoods[index] = val;
  529. that.setData({
  530. hotGoods: hotGoods
  531. });
  532. }
  533. }, that);
  534. }
  535. });
  536. },
  537. //购物车增加
  538. addNumber: function(e) {
  539. let that = this;
  540. var goodsId = e.currentTarget.dataset.goodsId;
  541. var productId = e.currentTarget.dataset.productId;
  542. var hotGoods = that.data.hotGoods;
  543. // hotGoods.forEach(function (val, index, arr) {
  544. // if (val.product_id == productId) {
  545. // val.cart_num = val.cart_num + 1;
  546. // hotGoods[index] = val;
  547. // }
  548. // });
  549. // that.setData({ hotGoods: hotGoods });
  550. util.request(api.CartAdd, {
  551. goodsId: goodsId,
  552. productId: productId,
  553. number: 1
  554. }, 'POST').then(function(res) {
  555. if (res.errno === 0 && null != res.data) {
  556. hotGoods.forEach(function(val, index, arr) {
  557. res.data.cartList.forEach(function(cartVal, cartIndex, cartArr) {
  558. if (val.product_id == cartVal.product_id) {
  559. val.cart_num = cartVal.number;
  560. hotGoods[index] = val;
  561. }
  562. });
  563. that.setData({
  564. hotGoods: hotGoods
  565. });
  566. }, that);
  567. wx.showToast({
  568. title: '添加成功'
  569. })
  570. } else {
  571. wx.showToast({
  572. title: res.errmsg,
  573. icon: 'none'
  574. })
  575. }
  576. });
  577. },
  578. // 查询是否有活动
  579. enableActivity: function() {
  580. let that = this;
  581. let couponIds = wx.getStorageSync('couponIds');
  582. if (!couponIds) {
  583. couponIds = new Array();
  584. }
  585. // util.request(api.EnableActivity, { couponIds: couponIds }).then(function (res) {
  586. // // if (res.errno === 0 && null != res.data.showCoupon) {
  587. // // if (couponIds.contains(res.data.showCoupon.id)) {
  588. // // return;
  589. // // }
  590. // // couponIds.push(res.data.showCoupon.id);
  591. // // wx.setStorageSync('couponIds', couponIds);
  592. // // that.setData({
  593. // // couponVo: res.data.showCoupon,
  594. // // showPop: true
  595. // // });
  596. // // } else
  597. // if (res.errno === 0 && null != res.data.takeCoupon && null != res.data.takeCoupon.id) {
  598. // that.setData({
  599. // couponVo: res.data.takeCoupon,
  600. // showPop: true
  601. // });
  602. // }
  603. // });
  604. },
  605. // 商品扫码
  606. scanGoodsCode: function(e) {
  607. var that = this;
  608. var code;
  609. var value;
  610. var substrValue;
  611. var scanType;
  612. // 调起客户端扫码界面进行扫码
  613. wx.scanCode({
  614. // 是否只能从相机扫码
  615. onlyFromCamera: true,
  616. // 扫码类型, barCode:一维码, qrCode:二维码
  617. scanType: ['barCode', 'qrCode'],
  618. success: function(res) {
  619. that.code = "结果:" + res.result + ",路径:" + res.path + ",编码:" + res.rawData;
  620. that.value = res.result;
  621. that.scanType = res.scanType;
  622. that.setData({
  623. goodsCode: that.code
  624. });
  625. if (that.scanType == 'QR_CODE') { //二维码
  626. that.substrValue = that.value.substring(0, 5);
  627. that.value = that.value.substring(5, that.value.length);
  628. // var goodId = that.value.substring(18, that.value.length);
  629. var scanArray = that.value.split('&');
  630. // console.log(scanArray.length);
  631. if (scanArray.length < 2) {
  632. wx.showModal({
  633. title: '',
  634. content: '您所扫描的商品无效',
  635. showCancel: false
  636. });
  637. return;
  638. }
  639. var goodId = scanArray[0].substring(18, that.value.length);
  640. var storeId = scanArray[1].substring(8, that.value.length);
  641. // console.log("storeId:" + storeId);
  642. // console.log("goodId:" + goodId);
  643. if (that.substrValue != 'emato') { //../goods/goods?id=&merchSn=
  644. wx.showModal({
  645. title: '',
  646. content: '您所扫描的商品无效',
  647. showCancel: false,
  648. success: function(res) {
  649. if (res.confirm) {
  650. console.log('用户点击确定')
  651. } else if (res.cancel) {
  652. console.log('用户点击取消')
  653. }
  654. }
  655. });
  656. return;
  657. }
  658. if (storeId != wx.getStorageSync('storeId')) {
  659. wx.showModal({
  660. title: '扫描结果',
  661. content: '该商品不属于当前门店',
  662. showCancel: false
  663. });
  664. return;
  665. }
  666. util.request(api.GoodsDetail, {
  667. id: goodId,
  668. storeId: storeId,
  669. referrer: ''
  670. }).then(function(res) {
  671. if (res.errno === 0) {
  672. // console.log(res);
  673. // 跳转页面
  674. setTimeout(function() {
  675. wx.navigateTo({
  676. url: that.value,
  677. success: function(e) {
  678. console.log('跳转成功');
  679. },
  680. fail: function(e) {
  681. console.log('跳转失败');
  682. }
  683. })
  684. }, 350)
  685. } else {
  686. wx.showModal({
  687. title: '扫描结果',
  688. content: '商品不存在',
  689. showCancel: false
  690. });
  691. }
  692. });
  693. } else { //其他码
  694. //弹框显示结果
  695. wx.showModal({
  696. title: '扫描结果',
  697. content: that.value,
  698. showCancel: false
  699. });
  700. }
  701. },
  702. fail: function() {
  703. // 显示提示框
  704. wx.showToast({
  705. title: '扫码失败',
  706. icon: 'none',
  707. // 提示的延迟时间
  708. duration: 3000
  709. })
  710. }
  711. })
  712. },
  713. imgOnLoad: function(e) {
  714. let that = this;
  715. // console.log('图片加载完成');
  716. // var realthumb = e.target.dataset.thumb;
  717. // let list = that.data.list
  718. // for (var i = 0; i < list.length; i++) {
  719. // if (list[i].thumb == realthumb) {
  720. // list[i].loaded = true
  721. // }
  722. // that.setData({
  723. // list: list
  724. // })
  725. // }
  726. },
  727. switchAttrPop: function() {
  728. this.setData({
  729. openAttr: !this.data.openAttr
  730. })
  731. },
  732. hideSwitchAttrPop: function() {
  733. this.setData({
  734. openAttr: false
  735. })
  736. },
  737. //购物车增加
  738. addCart: function(e) {
  739. let that = this;
  740. that.setData({
  741. number: 1
  742. });
  743. var goodsId = e.currentTarget.dataset.goodsId;
  744. var retailPrice = e.currentTarget.dataset.retailPrice;
  745. util.request(api.GoodsSku, {
  746. goodsId: goodsId
  747. }).then(function(res) {
  748. if (res.errno === 0 && null != res.data) {
  749. that.setData({
  750. goodsVo: res.data.goodsVo,
  751. specificationList: res.data.specificationList,
  752. productList: res.data.productList,
  753. openAttr: !that.data.openAttr,
  754. retailPrice: retailPrice,
  755. stockNum: res.data.stockNum,
  756. cartNumber: res.data.cartNumber,
  757. checkedSpecText: res.data.specificationList[0].valueList[0].value
  758. });
  759. //
  760. let _specificationList = res.data.specificationList;
  761. for (let i = 0; i < _specificationList.length; i++) {
  762. if (_specificationList[i].valueList.length == 1) {
  763. //如果已经选中,则反选
  764. _specificationList[i].valueList[0].checked = true;
  765. }
  766. }
  767. that.setData({
  768. 'specificationList': _specificationList
  769. });
  770. }
  771. });
  772. },
  773. shows: function(e) {
  774. // wx.redirectTo({
  775. // url: '/pages/images/images'
  776. // })
  777. wx.navigateTo({
  778. url: '../ucenter/campMinus/campMinus?campMinusId=' + 9 + '&&storeId=' + 8 + '&&campName=' + '满200减50' + "&&isShare=1"
  779. })
  780. },
  781. onReachBottom() {
  782. var that = this;
  783. if (that.data.list.length > 0) {
  784. // console.log(that.data.list)
  785. wx.showLoading({
  786. title: '加载中...',
  787. })
  788. }
  789. that.setData({
  790. page: that.data.page + 1
  791. });
  792. that.getGoodsList();
  793. }
  794. })