index.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. import Vue from 'vue'
  2. import Vuex from 'vuex';
  3. import $http from '../utils/http.js'
  4. import $util from '../utils/util.js'
  5. Vue.use(Vuex)
  6. const store = new Vuex.Store({
  7. state: {
  8. setColor: '',
  9. color: '#a07c5a',
  10. is_show: false,
  11. userInfo: uni.getStorageSync('userInfo') || '',
  12. prevent: true,
  13. store_id: '',
  14. table_id: '',
  15. turntable_id: '',
  16. systemInfo: {},
  17. teen_index: 1,
  18. address: {},
  19. app_id: '',
  20. tabActive: 1,
  21. is_Refresh: true,
  22. cate_id: null,
  23. dining_index: 1,
  24. couponList: [],
  25. audioList: [],
  26. swiperList: [],
  27. is_business: true,
  28. is_creatOrder: false, //更新购物车
  29. descFood: {},
  30. // descTake:"外卖",
  31. descOrder: {},
  32. merchant_id:null,
  33. vx_carGoods:[],
  34. },
  35. getters: {
  36. systemInfo(state) {
  37. return state.systemInfo
  38. },
  39. userInfo(state) {
  40. return state.userInfo
  41. },
  42. store_id(state) {
  43. return state.store_id
  44. },
  45. },
  46. mutations: {
  47. SET_CARGOODS(state, desc){
  48. state.vx_carGoods = desc
  49. },
  50. // 分账号授权id
  51. SET_MERCHANT_ID(state, desc){
  52. state.merchant_id = desc
  53. },
  54. // 下单页面文字
  55. SET_ORDER(state, desc) {
  56. state.descOrder = desc
  57. },
  58. // 点餐页面文字
  59. SET_DESC(state, desc) {
  60. state.descFood = desc
  61. },
  62. // 更新购物车
  63. SET_CREAT(state, creat) {
  64. state.is_creatOrder = creat
  65. },
  66. // 营业时间
  67. SET_BUSINESS(state, checked) {
  68. state.is_business = checked
  69. },
  70. // 弹窗优惠劵列表
  71. SET_SWIPER(state, list) {
  72. state.swiperList = list;
  73. },
  74. // 弹窗语音列表
  75. SET_AUDIO(state, list) {
  76. state.audioList = list;
  77. },
  78. // 弹窗优惠劵列表
  79. SET_COUPON(state, list) {
  80. state.couponList = list;
  81. },
  82. // 堂食1、自提2
  83. SET_SELFMENTION(state, index) {
  84. state.dining_index = index;
  85. },
  86. // 分类id SET_CATE_ID
  87. SET_CATE_ID(state, id) {
  88. // console.log(id, "cate_idcate_id")
  89. state.cate_id = id;
  90. },
  91. //支付宝切换页面标题名称不隐藏
  92. SET_REFRESH(state, Refresh) {
  93. state.is_Refresh = Refresh;
  94. },
  95. //订单状态跳转1已完成,2待完成
  96. SET_TABACTIVE(state, tabActive) {
  97. state.tabActive = tabActive;
  98. },
  99. // 设置颜色
  100. SET_MONITOR_COLOR(state, color) {
  101. state.setColor = color;
  102. state.color = color;
  103. },
  104. //门店id
  105. SET_STORE_ID: (state, store_id) => {
  106. state.store_id = store_id;
  107. uni.setStorageSync('store_id', store_id)
  108. },
  109. // 设置餐桌id
  110. SET_TABLE_ID: (state, table_id) => {
  111. state.table_id = table_id;
  112. uni.setStorageSync('table_id', table_id)
  113. },
  114. // 大转盘id
  115. SET_TURNTABLE_ID: (state, turntable_id) => {
  116. state.turntable_id = turntable_id;
  117. uni.setStorageSync('turntable_id', turntable_id)
  118. },
  119. // 获取配置信息
  120. SET_SYSTEM: (state, system) => {
  121. state.systemInfo = system;
  122. uni.setStorageSync('systemInfo', system)
  123. },
  124. // 获取用户信息
  125. SET_USER_INFO: (state, userInfo) => {
  126. state.userInfo = userInfo;
  127. uni.setStorageSync('userInfo', userInfo)
  128. uni.setStorageSync('user_id', userInfo.id)
  129. },
  130. // 获取堂食/外卖
  131. SET_TEEN_INDEX: (state, index) => {
  132. // console.log(index, "SET_TEEN_INDEX")
  133. state.teen_index = index;
  134. },
  135. // 获取堂食/自提
  136. SET_MENTION: (state, index) => {
  137. state.teen_index = index;
  138. },
  139. // 地址
  140. SET_ADDRESS(state, address) {
  141. state.address = address
  142. },
  143. // 全局appid
  144. SET_APP_ID(state, id) {
  145. state.app_id = id
  146. },
  147. // 获取手机授权弹窗
  148. showAttrPicker(state, picker) {
  149. state.is_show = picker;
  150. },
  151. // 重置扫码进入获取到的门店id
  152. SET_PREVENT(state, prevent) {
  153. state.prevent = prevent;
  154. },
  155. },
  156. actions: {
  157. // 获取颜色
  158. getSystemColor({
  159. commit,
  160. state
  161. }) {
  162. if (!state.store_id) {
  163. return
  164. }
  165. $http.request('xcx/store_color', {
  166. store_id: state.store_id,
  167. }, true).then(res => {
  168. commit('SET_MONITOR_COLOR', res.data.color || '#3387FF')
  169. })
  170. },
  171. // 获取店铺信息
  172. async getSystemStup({
  173. commit,
  174. state
  175. }) {
  176. if (!state.store_id) {
  177. return
  178. }
  179. await $http.request('xcx/system', {
  180. store_id: state.store_id,
  181. table_id: state.table_id,
  182. }, true).then(res => {
  183. // console.log(state.store_id,"state.store_id")
  184. let set_index = res.data.is_hall==1?1:res.data.is_waimai==1?2:res.data.is_ziti==1?3:0;
  185. // console.log("systemData",res.data);
  186. commit('SET_TEEN_INDEX', set_index);
  187. commit('SET_TABLE_ID', res.data.table_id)
  188. commit('SET_SYSTEM', res.data)
  189. commit('SET_PREVENT', false)
  190. if (res.data.set.desc) {
  191. var desc = {
  192. food1: res.data.set.desc.split(",")[0] || '下单',
  193. food2: res.data.set.desc.split(",")[1] || '配送'
  194. }
  195. } else {
  196. var desc = {
  197. food1: '下单',
  198. food2: '配送'
  199. }
  200. }
  201. commit('SET_DESC', desc)
  202. if (res.data.set.eat_mode) {
  203. var desc = {
  204. title: res.data.set.eat_mode.split(",")[0] || '购买方式',
  205. food1: res.data.set.eat_mode.split(",")[1] || '店内下单',
  206. food2: res.data.set.eat_mode.split(",")[2] || '到店自取',
  207. }
  208. } else {
  209. var desc = {
  210. title: '购买方式',
  211. food1: '店内下单',
  212. food2: '到店自取'
  213. }
  214. }
  215. commit('SET_ORDER', desc)
  216. $http.request('xcx/template', {
  217. admin_id: res.data.admin_id,
  218. }, true).then(r => {
  219. if (r.code == '200') {
  220. uni.setStorageSync('balance_subscribe', r.data)
  221. }
  222. })
  223. let {
  224. time_content,
  225. is_rest
  226. } = res.data;
  227. function nowTime() { //获取当前时间
  228. let now = new Date();
  229. let _hour = (10 > now.getHours()) ? '0' + now.getHours() : now.getHours();
  230. let _minute = (10 > now.getMinutes()) ? '0' + now.getMinutes() : now
  231. .getMinutes();
  232. let _second = (10 > now.getSeconds()) ? '0' + now.getSeconds() : now
  233. .getSeconds();
  234. return _hour + ':' + _minute + ':' + _second;
  235. }
  236. // is_rest==1休息 2设置休息时间
  237. if (is_rest == 2) {
  238. // console.log("设置休息时间",time_content)
  239. if (!time_content) {
  240. commit('SET_BUSINESS', true)
  241. } else {
  242. for (let i of time_content) {
  243. commit('SET_BUSINESS', false)
  244. if ($util.time_range(i.start, i.end, nowTime())) {
  245. commit('SET_BUSINESS', true)
  246. return
  247. }
  248. }
  249. }
  250. }
  251. if (is_rest == 1) {
  252. commit('SET_BUSINESS', false)
  253. }
  254. })
  255. },
  256. // 获取用户信息
  257. async getOpenid({
  258. commit,
  259. state
  260. }) {
  261. // #ifdef H5
  262. //临时用户信息配置
  263. // let tempCode="0d1YErFa1uLuhG0i3vGa1ZleM21YErFZ";
  264. let openid="obOpI5GhysDLz6F7neu8RkNdeew8";
  265. let params = {
  266. openid: openid,
  267. type: 1,
  268. store_id: state.store_id
  269. }
  270. $http.request('xcx/login', params, true).then(
  271. res => {
  272. commit('SET_USER_INFO', res.data)
  273. // 获取默认地址
  274. // console.log("获取默认地址")
  275. $http.request('xcx/MyDefaultAddress', {
  276. user_id: res.data.id,
  277. }, true).then(res => {
  278. commit('SET_ADDRESS', res.data)
  279. }).catch(err => {})
  280. }).catch(err => {})
  281. // $http.request('xcx/openid', {
  282. // appid: state.app_id || '',
  283. // code: tempCode,
  284. // type:1,
  285. // store_id: state.store_id
  286. // }, true).then(res => {
  287. // // console.log(res.data,"data")
  288. // uni.setStorageSync('user_xcx_info', res.data);
  289. // })
  290. // #endif
  291. // #ifndef H5
  292. uni.login({
  293. success: res => {
  294. console.log("start",res);
  295. let type, info = {};
  296. // #ifdef MP-WEIXIN
  297. type = 1
  298. // #endif
  299. // #ifdef MP-ALIPAY
  300. type = 2
  301. // #endif
  302. // console.log(res.code,"code")
  303. $http.request('xcx/openid', {
  304. appid: state.app_id || '',
  305. code: res.code,
  306. type,
  307. store_id: state.store_id
  308. }, true).then(res => {
  309. // console.log(res.data,"data")
  310. uni.setStorageSync('user_xcx_info', res.data);
  311. let params;
  312. // #ifdef MP-WEIXIN
  313. params = {
  314. openid: res.data.openid,
  315. type: 1,
  316. store_id: state.store_id
  317. }
  318. // #endif
  319. // #ifdef MP-ALIPAY
  320. params = {
  321. appid: state.app_id || '',
  322. user_id: res.data.user_id,
  323. type: 2,
  324. store_id: state.store_id
  325. }
  326. // #endif
  327. $http.request('xcx/login', params, true).then(
  328. res => {
  329. commit('SET_USER_INFO', res.data)
  330. // 获取默认地址
  331. // console.log("获取默认地址")
  332. $http.request('xcx/MyDefaultAddress', {
  333. user_id: res.data.id,
  334. }, true).then(res => {
  335. commit('SET_ADDRESS', res.data)
  336. }).catch(err => {})
  337. }).catch(err => {})
  338. })
  339. },
  340. complete: res => {}
  341. })
  342. // #endif
  343. },
  344. }
  345. })
  346. export default store