store.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var app = getApp()
  4. Page({
  5. data: {
  6. selected: 0,
  7. groupList: [],
  8. scrollTop: 0,
  9. pickerName: '其他地址',
  10. nearStoreList: [],
  11. cityStoreList: [],
  12. region: [],
  13. },
  14. bindRegionChange: function (e) {
  15. console.log('picker发送选择改变,携带值为', e.detail.value)
  16. this.setData({
  17. pickerName: e.detail.value[0] + '-' + e.detail.value[1] + '-' + e.detail.value[2]
  18. })
  19. let that = this;
  20. util.request(api.StoreByCity, { provinceName: e.detail.value[0], cityName: e.detail.value[1], countyName: e.detail.value[2] }).then(function (res) {
  21. if (res.errno === 0) {
  22. that.setData({
  23. cityStoreList: res.data
  24. })
  25. }
  26. });
  27. },
  28. handleTag(e) {
  29. this.setData({
  30. selected: e.currentTarget.dataset.index
  31. })
  32. },
  33. chooseStore(e) {
  34. console.log(e.currentTarget.dataset.item)
  35. let item = e.currentTarget.dataset.item;
  36. let that = this;
  37. util.request(api.ChooseStoreId, { storeId: item.id }, 'POST').then(function (res) {
  38. if (res.errno === 0) {
  39. wx.setStorageSync('storeId', item.id);
  40. for (var i = 0; i < that.data.cityStoreList.length; i++) {
  41. if (item.id == that.data.cityStoreList[i].id) {
  42. wx.setStorageSync('storeVo', JSON.stringify(that.data.cityStoreList[i]));
  43. }
  44. }
  45. for (var i = 0; i < that.data.nearStoreList.length; i++) {
  46. if (item.id == that.data.nearStoreList[i].id) {
  47. wx.setStorageSync('storeVo', JSON.stringify(that.data.nearStoreList[i]));
  48. }
  49. }
  50. var pages = getCurrentPages();
  51. var currPage = pages[pages.length - 1];  //当前页面
  52. var prevPage = pages[pages.length - 2]; //上一个页面
  53. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  54. prevPage.setData({
  55. storeName: item.storeName
  56. })
  57. prevPage.getIndexData();
  58. prevPage.enableActivity();
  59. prevPage.getGroupData();
  60. wx.navigateBack()
  61. }
  62. })
  63. },
  64. onLoad: function (options) {
  65. // 页面初始化 options为页面跳转所带来的参数
  66. let nearStoreList = wx.getStorageSync('nearStoreList') ? JSON.parse(wx.getStorageSync('nearStoreList')) : [];
  67. this.setData({
  68. nearStoreList: nearStoreList
  69. })
  70. },
  71. onReady: function () {
  72. // 页面渲染完成
  73. },
  74. onShow: function () {
  75. // 页面显示
  76. },
  77. onHide: function () {
  78. // 页面隐藏
  79. },
  80. onUnload: function () {
  81. // 页面关闭
  82. }
  83. })