PageSourceSearch

https://samurai.ru/local/templates/new_design/state/index.js

js samurai.ru collected 2026-10-01 23:55:49 UTC 6,671 bytes, 238 lines download raw bytes

1import api from "../libs/api/index.js";
2import customFunctions from "../libs/customFunctions.js";
3import basket from "./basket/index.js?v=1";
4import catalog from "./catalog/index.js";
5import user from "./user/index.js?v=13";
6import order from "./order/index.js";
7import modals_state from "./modals_state/index.js";
8import stocks from "./stocks/index.js";
9
10const getQueryParams = (paramName) => {
11  const queryString = window.location.search;
12  const urlParams = new URLSearchParams(queryString);
13  return urlParams.get(paramName);
14};
15
16
17
18export default new Vuex.createStore({
19  state: {
20    error: { show: false, message: "" },
21    cities: [],
22    allModals: [],
23    polygons: false,
24  },
25  getters: {
26    GET_CITIES(state) {
27      return state.cities;
28    },
29    GET_NO_SCROLLING(state) {
30      return Boolean(state.allModals.length);
31    },
32    GET_NO_SCROLLING_ARRAY(state) {
33      return state.allModals;
34    },
35    GET_POLYGONS(state) {
36      return state.polygons;
37    }
38  },
39
40  mutations: {
41    createErrorPopupData(state, message) {
42      state.error.message = message;
43      state.error.show = true;
44    },
45    SET_CITIES(state, cities) {
46      state.cities = cities;
47    },
48    SET_POLYGONS(state, polygons) {
49      state.polygons = polygons;
50    }
51  },
52  actions: {
53    addModal(ctx, key) {
54      ctx.state.allModals.push(key);
55    },
56
57    removeModal(ctx, key) {
58      ctx.state.allModals = ctx.state.allModals.filter((item) => {
59        return key != item;
60      });
61    },
62
63    async reissueCode(ctx) {
64      (await api.get("?request=reissue_sms_code"));
65    },
66
67    showError(ctx, message) {
68      ctx.commit("createErrorPopupData", message);
69    },
70    async initAddresses(ctx) {
71      let cities = (await api.get("?request=get_towns")).data;
72      if (cities.state) {
73        ctx.commit(
74          "SET_CITIES",
75          customFunctions.normalizeArray(Object.values(cities.data))
76        );
77      }
78    },
79
80    async checkAddress(ctx, data) {
81      let responce = (
82        await api.post("?request=check_delivery_rule", data, {
83          headers: {
84            "Content-Type": "application/x-www-form-urlencoded",
85          },
86        })
87      ).data;
88
89      return responce.data;
90    },
91
92    async set_address(ctx, { address_data, address_type = "delivery_old" }) {
93      let responce;
94      try {
95        switch (address_type) {
96          case "delivery_old": {
97            responce = (
98              await api.post(
99                "?request=address_set",
100                { zone_id: address_data },
101                {
102                  headers: {
103                    "Content-Type": "application/x-www-form-urlencoded",
104                  },
105                }
106              )
107            ).data;
108            break;
109          }
110          case "delivery_new": {
111            responce = (
112              await api.post(
113                "?request=address_new",
114                { address: JSON.stringify(address_data) },
115                {
116                  headers: {
117                    "Content-Type": "application/x-www-form-urlencoded",
118                  },
119                }
120              )
121            ).data;
122            break;
123          }
124          case "pickup_point": {
125            responce = (
126              await api.post(
127                "?request=address_pickup_set",
128                { point_id: address_data },
129                {
130                  headers: {
131                    "Content-Type": "application/x-www-form-urlencoded",
132                  },
133                }
134              )
135            ).data;
136            if(responce.data && responce.data.redirect_url) {
137              window.location.href = window.location.href.replace(
138                window.location.hostname,
139                responce.data.redirect_url
140              );
141            }
142            break;
143          }
144        }
145        
146        customFunctions.checkState(responce);
147
148        ctx.dispatch("initUser");
149        ctx.dispatch("initBasket");
150        return true;
151      } catch (error) {
152        const message = customFunctions.checkResponceError(error);
153        ctx.dispatch("showError", message);
154        return false;
155      }
156    },
157    async getAddressByCoordinates(ctx, coord) {
158      const suggestions = (
159        await api.post(
160          "https://suggestions.dadata.ru/suggestions/api/4_1/rs/geolocate/address",
161          {
162            count: 1,
163            lat: coord.lat,
164            lon: coord.lon,
165            radius_meters: 70,
166          },
167          {
168            headers: {
169              authorization: "Token fecc8692fbd4ee158bff27753e5fb86889188868",
170            },
171          }
172        )
173      ).data.suggestions;
174      return suggestions[0];
175    },
176
177    async getPolygons(ctx) {
178      let responce = (await api.get("?request=get_delivery_polygons")).data;
179
180      customFunctions.checkState(responce);
181
182      ctx.commit("SET_POLYGONS", responce.data);
183    },
184
185    async init(ctx) {
186      let pathName = window.location.pathname;
187
188      await ctx.dispatch("initAddresses");
189      await ctx.dispatch("get_payments_methods");
190      await ctx.dispatch("initUser");
191      await ctx.dispatch("initCatalog");
192      await ctx.dispatch("initBasket");
193      await ctx.dispatch("initCatchMomentData");
194
195      if (pathName == `/personal/order/check/`) {
196        ctx.dispatch(`getOrder`, getQueryParams('id'));
197      }
198
199      if (pathName == `/delivery/stocks/` || pathName == "/delivery/delivery-menu/") {
200        let stockId = getQueryParams('stock');
201        
202        if (stockId != null) {
203          ctx.dispatch(`getDetailStock`, { stockId });
204        }
205      }
206      if (pathName == "/delivery/delivery-menu/") {
207        let productId = getQueryParams('product');
208        let products = ctx.rootState.catalog.products.filter(product => { return product.id == productId });
209
210        if (products.length) {
211          {
212            ctx.dispatch(`openDetailCard`, products[0]);
213          }
214        }
215
216        await ctx.dispatch(`initLastOrderThisDay`);
217      }
218      if (pathName == `/cafe/`) {
219        let stockId = getQueryParams('stock');
220        if (stockId != null) {
221          ctx.dispatch(`getDetailStock`, { stockId, cafe: true });
222        }
223      }
224      if (pathName == `/personal/`) {
225          await ctx.dispatch(`initDynamicBonusProgressBar`);
226          await ctx.dispatch(`initBonusHistory`);
227      }
228    },
229  },
230  modules: {
231    user,
232    catalog,
233    order,
234    basket,
235    modals_state,
236    stocks,
237  },
238});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.