123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- // store/modules/shop.js
- let defaultUrl="https://img.zcool.cn/community/0179cc57debf250000018c1b6c5903.jpg@1280w_1l_2o_100sh.jpg"
- let defaultInfo="这家店暂时没有什么可以说的和展示的"
- export default {
- namespaced: true,
- state: () => ({
- shops: [{
- "id": 1,
- "storeName": "淮瑞菜记-枫林店",
- "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
- "keeperId": 5,
- "username": null,
- "keeperName": null,
- "phone": null,
- "email": null,
- "imgUrl":defaultUrl,
- "shopInfo":defaultInfo,
- "icon":"../../static/logo.png"
- },
- {
- "id": 2,
- "name": "淮瑞咖啡-经开店",
- "address": "江西省南昌市经济开发区双港西大街绿地悦公馆",
- "keeperId": 1,
- "username": null,
- "keeperName": null,
- "phone": null,
- "email": null,
- "imgUrl":defaultUrl,
- "shopInfo":defaultInfo,
- "icon":"../../static/logo.png"
- },
- {
- "id": 3,
- "name": "淮瑞咖啡-枫林店",
- "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
- "keeperId": 2,
- "username": null,
- "keeperName": null,
- "phone": null,
- "email": null,
- "imgUrl":defaultUrl,
- "shopInfo":defaultInfo,
- "icon":"../../static/logo.png"
- },
- {
- "id": 4,
- "storeName": "淮瑞咖啡-枫林店",
- "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
- "keeperId": 3,
- "username": null,
- "keeperName": null,
- "phone": null,
- "email": null,
- "imgUrl":defaultUrl,
- "shopInfo":defaultInfo,
- "icon":"../../static/logo.png"
- },
- {
- "id": 5,
- "name": "淮瑞咖啡-枫林店",
- "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
- "keeperId": 4,
- "username": null,
- "keeperName": null,
- "phone": null,
- "email": null,
- "imgUrl":defaultUrl,
- "shopInfo":defaultInfo,
- "icon":"../../static/logo.png"
- },
- {
- "id": 6,
- "name": "淮瑞咖啡-枫林店",
- "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
- "keeperId": 5,
- "username": null,
- "keeperName": null,
- "phone": null,
- "email": null,
- "imgUrl":defaultUrl,
- "shopInfo":defaultInfo,
- "icon":"../../static/logo.png"
- },
- {
- "id": 7,
- "name": "淮瑞咖啡-枫林店",
- "address": "江西省南昌市经济开发区枫林大道江西财经大学店",
- "keeperId": 6,
- "username": null,
- "keeperName": null,
- "phone": null,
- "email": null,
- "imgUrl":defaultUrl,
- "shopInfo":defaultInfo,
- "icon":"../../static/logo.png"
- }
- ] // 保存店面数据的数组
- }),
- mutations: {
- setShops(state, shops) {
- state.shops = shops; // 更新店面数据
- }
- },
- actions: {
- //后端请求得到所有的店面的数据,保存入shops
- async fetchShops({ commit }) {
- // return
- console.log( uni.$http.baseUrl + 'store/selectAll')
- try {
- const response = await uni.request({
- url: uni.$http.baseUrl + 'store/selectAll',
- method: 'GET',
- header: {
- 'content-type': 'application/json',
- 'token': uni.$http.testToken
- }
- });
- if (response.data && response.data.code === '200') {
- // 如果请求成功并且返回的数据中包含 code 为 '200',则提交 mutation 更新店面数据
- commit('setShops', response.data.data);
- console.log(response.data.data,"aaa")
- } else {
- console.error('请求失败或返回的数据不符合预期');
- }
- } catch (error) {
- console.error('请求失败:', error);
- }
- }
- },
- getters: {
- getShopById: (state) => (id) => {
- console.log(id);
- return state.shops.find(shop => shop.id == id)
- },
- getShowShops: (state) => {
- return state.shops
- },
- getDistance: (state) => (id) => {
- console.log('来了')
- // return state.shops.find(shop => shop.id == id).distance
- return 960
- },
- getTypeById: (state) => (id) => {
- return state.shops.find(shop => shop.id === id).productTypes
- },
- getProductById: (state) => (id) => {
- return state.shops.find(shop => shop.id === id).products
- }
- // getShopById(state , shopId,prarm3,prarm4){
- // console.log(state);
- // console.log(shopId);
- // console.log(prarm3);
- // console.log(prarm4);
- // console.log('-----------');
- // shopId=2
- // // 从 shops 数组中查找与指定 id 相匹配的店面信息
- // console.log(state.shops);
- // let shops=state.shops
- // for (let idx in shops) {
- // console.log(idx);
- // // console.log(shops[idx].id==shopId);
- // console.log(shops[idx].id,shops[idx].id==shopId,shopId);
- // if (shops[idx].id==shopId){
- // let shop =shops[idx]
- // return shop
- // }
- // }
- // console.log(data);
- // return data
- // }
- // getShopById: (state) => (shopId) => {
- // console.log(shopId);
- // // 从 shops 数组中查找与指定 id 相匹配的店面信息
- // console.log(state.shops);
- // let shops = state.shops;
- // for (let idx in shops) {
- // console.log(idx);
- // console.log(shops[idx].id == shopId);
- // console.log(shops[idx].id, shops[idx].id == shopId, shopId);
- // if (shops[idx].id == shopId) {
- // let shop = shops[idx];
- // return shop;
- // }
- // }
- // }
- },
- };
|