index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. storeId: '',
  9. current: null,
  10. store: null,
  11. activeColor:''
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: async function (options) {
  17. this.setData({
  18. activeColor:getApp().globalData.activeColor || '#229293'
  19. })
  20. let storeID = options.store
  21. await this.getShopStore()
  22. await this.getBindStore()
  23. },
  24. // 获取所有店铺信息
  25. getShopStore: async function () {
  26. let Store = new Parse.Query('ShopStore')
  27. Store.notEqualTo('isDeleted', "true")
  28. Store.equalTo('company', company)
  29. Store.equalTo('type', 'shop')
  30. Store.descending('createdAt')
  31. let store = await Store.find()
  32. let list = []
  33. store.forEach(val => {
  34. val = val.toJSON()
  35. list.push(val)
  36. })
  37. let current = list.filter(val => {
  38. return val.objectId == this.data.storeID
  39. })[0]
  40. this.setData({
  41. store: list,
  42. current: current
  43. })
  44. },
  45. // 获取当前绑定的店铺
  46. getBindStore: async function () {
  47. let storeID = wx.getStorageSync('storeID');
  48. let Store = new Parse.Query('ShopStore')
  49. let store = await Store.get(storeID)
  50. let storeJSON = store.toJSON()
  51. this.setData({
  52. current: storeJSON
  53. })
  54. },
  55. // 点击店铺绑定
  56. bindStore(e) {
  57. let id = e.currentTarget.dataset.id
  58. wx.setStorageSync('storeID', id);
  59. wx.navigateBack({
  60. delta: 1,
  61. });
  62. setTimeout(() => {
  63. wx.showToast({
  64. title: '选择完毕',
  65. icon: 'success',
  66. duration: 1500,
  67. });
  68. }, 200)
  69. },
  70. /**
  71. * 生命周期函数--监听页面初次渲染完成
  72. */
  73. onReady: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面显示
  77. */
  78. onShow: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function () {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function () {
  99. },
  100. /**
  101. * 用户点击右上角分享
  102. */
  103. onShareAppMessage: function () {
  104. }
  105. })