1
0

store.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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, {
  38. storeId: item.id, merchSn: item.merchSn,
  39. isRefusedLogin: wx.getStorageSync('isRefusedLogin') }, 'POST').then(function (res) {
  40. if (res.errno === 0) {
  41. wx.setStorageSync('storeId', item.id);
  42. for (var i = 0; i < that.data.cityStoreList.length; i++) {
  43. if (item.id == that.data.cityStoreList[i].id) {
  44. wx.setStorageSync('storeVo', JSON.stringify(that.data.cityStoreList[i]));
  45. }
  46. }
  47. for (var i = 0; i < that.data.nearStoreList.length; i++) {
  48. if (item.id == that.data.nearStoreList[i].id) {
  49. wx.setStorageSync('storeVo', JSON.stringify(that.data.nearStoreList[i]));
  50. }
  51. }
  52. var pages = getCurrentPages();
  53. var currPage = pages[pages.length - 1];  //当前页面
  54. var prevPage = pages[pages.length - 2]; //上一个页面
  55. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  56. prevPage.setData({
  57. storeName: item.storeName
  58. })
  59. prevPage.getIndexData();
  60. prevPage.enableActivity();
  61. prevPage.getGroupData();
  62. wx.navigateBack()
  63. }
  64. })
  65. },
  66. onLoad: function (options) {
  67. // 页面初始化 options为页面跳转所带来的参数
  68. let nearStoreList = wx.getStorageSync('nearStoreList') ? JSON.parse(wx.getStorageSync('nearStoreList')) : [];
  69. this.setData({
  70. nearStoreList: nearStoreList
  71. })
  72. },
  73. onReady: function () {
  74. // 页面渲染完成
  75. },
  76. onShow: function () {
  77. // 页面显示
  78. },
  79. onHide: function () {
  80. // 页面隐藏
  81. },
  82. onUnload: function () {
  83. // 页面关闭
  84. }
  85. })