shop.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // store/modules/shop.js
  2. let defaultUrl="https://img.zcool.cn/community/0179cc57debf250000018c1b6c5903.jpg@1280w_1l_2o_100sh.jpg"
  3. let defaultInfo="这家店暂时没有什么可以说的和展示的"
  4. export default {
  5. namespaced: true,
  6. state: () => ({
  7. shops: [{
  8. "id": 1,
  9. "storeName": "淮瑞菜记-枫林店",
  10. "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
  11. "keeperId": 5,
  12. "username": null,
  13. "keeperName": null,
  14. "phone": null,
  15. "email": null,
  16. "imgUrl":defaultUrl,
  17. "shopInfo":defaultInfo,
  18. "icon":"../../static/logo.png"
  19. },
  20. {
  21. "id": 2,
  22. "name": "淮瑞咖啡-经开店",
  23. "address": "江西省南昌市经济开发区双港西大街绿地悦公馆",
  24. "keeperId": 1,
  25. "username": null,
  26. "keeperName": null,
  27. "phone": null,
  28. "email": null,
  29. "imgUrl":defaultUrl,
  30. "shopInfo":defaultInfo,
  31. "icon":"../../static/logo.png"
  32. },
  33. {
  34. "id": 3,
  35. "name": "淮瑞咖啡-枫林店",
  36. "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
  37. "keeperId": 2,
  38. "username": null,
  39. "keeperName": null,
  40. "phone": null,
  41. "email": null,
  42. "imgUrl":defaultUrl,
  43. "shopInfo":defaultInfo,
  44. "icon":"../../static/logo.png"
  45. },
  46. {
  47. "id": 4,
  48. "storeName": "淮瑞咖啡-枫林店",
  49. "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
  50. "keeperId": 3,
  51. "username": null,
  52. "keeperName": null,
  53. "phone": null,
  54. "email": null,
  55. "imgUrl":defaultUrl,
  56. "shopInfo":defaultInfo,
  57. "icon":"../../static/logo.png"
  58. },
  59. {
  60. "id": 5,
  61. "name": "淮瑞咖啡-枫林店",
  62. "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
  63. "keeperId": 4,
  64. "username": null,
  65. "keeperName": null,
  66. "phone": null,
  67. "email": null,
  68. "imgUrl":defaultUrl,
  69. "shopInfo":defaultInfo,
  70. "icon":"../../static/logo.png"
  71. },
  72. {
  73. "id": 6,
  74. "name": "淮瑞咖啡-枫林店",
  75. "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
  76. "keeperId": 5,
  77. "username": null,
  78. "keeperName": null,
  79. "phone": null,
  80. "email": null,
  81. "imgUrl":defaultUrl,
  82. "shopInfo":defaultInfo,
  83. "icon":"../../static/logo.png"
  84. },
  85. {
  86. "id": 7,
  87. "name": "淮瑞咖啡-枫林店",
  88. "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
  89. "keeperId": 6,
  90. "username": null,
  91. "keeperName": null,
  92. "phone": null,
  93. "email": null,
  94. "imgUrl":defaultUrl,
  95. "shopInfo":defaultInfo,
  96. "icon":"../../static/logo.png"
  97. }
  98. ] // 保存店面数据的数组
  99. }),
  100. mutations: {
  101. setShops(state, shops) {
  102. state.shops = shops; // 更新店面数据
  103. }
  104. },
  105. actions: {
  106. //后端请求得到所有的店面的数据,保存入shops
  107. async fetchShops({ commit }) {
  108. // return
  109. console.log( uni.$http.baseUrl + 'store/selectAll')
  110. try {
  111. const response = await uni.request({
  112. url: uni.$http.baseUrl + 'store/selectAll',
  113. method: 'GET',
  114. header: {
  115. 'content-type': 'application/json',
  116. 'token': uni.$http.testToken
  117. }
  118. });
  119. if (response.data && response.data.code === '200') {
  120. // 如果请求成功并且返回的数据中包含 code 为 '200',则提交 mutation 更新店面数据
  121. commit('setShops', response.data.data);
  122. console.log(response.data.data,"aaa")
  123. } else {
  124. console.error('请求失败或返回的数据不符合预期');
  125. }
  126. } catch (error) {
  127. console.error('请求失败:', error);
  128. }
  129. }
  130. },
  131. getters: {
  132. getShopById: (state) => (id) => {
  133. console.log(id);
  134. return state.shops.find(shop => shop.id == id)
  135. },
  136. getShowShops: (state) => {
  137. return state.shops
  138. },
  139. getDistance: (state) => (id) => {
  140. console.log('来了')
  141. // return state.shops.find(shop => shop.id == id).distance
  142. return 960
  143. },
  144. getTypeById: (state) => (id) => {
  145. return state.shops.find(shop => shop.id === id).productTypes
  146. },
  147. getProductById: (state) => (id) => {
  148. return state.shops.find(shop => shop.id === id).products
  149. }
  150. // getShopById(state , shopId,prarm3,prarm4){
  151. // console.log(state);
  152. // console.log(shopId);
  153. // console.log(prarm3);
  154. // console.log(prarm4);
  155. // console.log('-----------');
  156. // shopId=2
  157. // // 从 shops 数组中查找与指定 id 相匹配的店面信息
  158. // console.log(state.shops);
  159. // let shops=state.shops
  160. // for (let idx in shops) {
  161. // console.log(idx);
  162. // // console.log(shops[idx].id==shopId);
  163. // console.log(shops[idx].id,shops[idx].id==shopId,shopId);
  164. // if (shops[idx].id==shopId){
  165. // let shop =shops[idx]
  166. // return shop
  167. // }
  168. // }
  169. // console.log(data);
  170. // return data
  171. // }
  172. // getShopById: (state) => (shopId) => {
  173. // console.log(shopId);
  174. // // 从 shops 数组中查找与指定 id 相匹配的店面信息
  175. // console.log(state.shops);
  176. // let shops = state.shops;
  177. // for (let idx in shops) {
  178. // console.log(idx);
  179. // console.log(shops[idx].id == shopId);
  180. // console.log(shops[idx].id, shops[idx].id == shopId, shopId);
  181. // if (shops[idx].id == shopId) {
  182. // let shop = shops[idx];
  183. // return shop;
  184. // }
  185. // }
  186. // }
  187. },
  188. };