酒店桌布为微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
3.9 KiB

9 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
9 months ago
8 months ago
7 months ago
8 months ago
8 months ago
9 months ago
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex); //vue的插件机制
  4. import api from '@/api/api.js'
  5. import Position from '@/utils/position.js'
  6. //Vuex.Store 构造器选项
  7. const store = new Vuex.Store({
  8. state: {
  9. configList: [], //配置列表
  10. shop : false,
  11. position : {//定位信息
  12. latitude : 0,
  13. longitude : 0,
  14. },
  15. userInfo : {},//用户信息
  16. bindShop : {},//酒店绑定的水洗店
  17. statistics : {},//水洗店查询首页统计
  18. category : [],//分类
  19. },
  20. getters: {
  21. // 角色 true为水洗店 false为酒店
  22. userShop(state){
  23. return state.shop
  24. }
  25. },
  26. mutations: {
  27. // 初始化配置
  28. initConfig(state){
  29. // api('getConfig', res => {
  30. // if(res.code == 200){
  31. // state.configList = res.result
  32. // }
  33. // })
  34. let config = ['getPrivacyPolicy', 'getUserAgreement']
  35. config.forEach(k => {
  36. api(k, res => {
  37. if (res.code == 200) {
  38. state.configList[k] = res.result
  39. }
  40. })
  41. })
  42. },
  43. //获取绑定店铺的数据
  44. getBindShop(state){
  45. api('bindShop', res => {
  46. if(res.code == 200){
  47. state.bindShop = res.result
  48. }
  49. })
  50. },
  51. // 水洗店查询首页统计
  52. getLaundryStoreHomeData(state){
  53. api('laundryStoreHomeData', {}, res => {
  54. uni.stopPullDownRefresh()
  55. if(res.code == 200){
  56. state.statistics = res.result
  57. }
  58. })
  59. },
  60. // 获取分类
  61. categoryList(state){
  62. api('categoryList', res => {
  63. if(res.code == 200){
  64. state.category = res.result
  65. }
  66. })
  67. },
  68. // 账号密码登录
  69. accountLogin(state, form){
  70. api('wxLogin', {
  71. latitude : state.position.latitude,
  72. longitude : state.position.longitude,
  73. loginType : 1,
  74. ...form,
  75. }, res => {
  76. if(res.code == 200){
  77. uni.setStorageSync('token', res.result.token)
  78. state.userInfo = res.result.userInfo
  79. state.shop = true
  80. uni.redirectTo({
  81. url: '/pages/index/index'
  82. })
  83. }
  84. })
  85. },
  86. login(state){
  87. let self = this
  88. uni.showLoading({
  89. title: '登录中...'
  90. })
  91. uni.login({
  92. success(res) {
  93. if(res.errMsg != "login:ok"){
  94. return
  95. }
  96. api('wxLogin', {
  97. code : res.code,
  98. latitude : state.position.latitude,
  99. longitude : state.position.longitude,
  100. loginType : 0,
  101. }, res => {
  102. uni.hideLoading()
  103. if(res.code != 200){
  104. return
  105. }
  106. state.userInfo = res.result.userInfo
  107. // state.shop = !!state.userInfo.shop
  108. uni.setStorageSync('token', res.result.token)
  109. self.commit('getUserInfo')
  110. if(!state.userInfo.nickName || !state.userInfo.headImage){
  111. uni.navigateTo({
  112. url: '/pages_order/auth/wxUserInfo'
  113. })
  114. }else{
  115. uni.navigateBack(-1)
  116. }
  117. })
  118. }
  119. })
  120. },
  121. getUserInfo(state){
  122. api('getInfo', res => {
  123. if(res.code == 200){
  124. state.userInfo = res.result
  125. state.shop = !!state.userInfo.shop
  126. if(state.shop){
  127. // 查询水洗店首页统计
  128. this.commit('getLaundryStoreHomeData')
  129. }else{
  130. //获取绑定店铺的数据
  131. this.commit('getBindShop')
  132. }
  133. }
  134. })
  135. },
  136. getPosition(state){
  137. Position.getLocation(res => {
  138. console.log(res);
  139. state.position = res
  140. })
  141. // console.log('wx.getFuzzyLocation');
  142. // uni.getFuzzyLocation({
  143. // type: 'wgs84',
  144. // isHighAccuracy: true,
  145. // highAccuracyExpireTime: 1000,
  146. // success (res) {
  147. // const latitude = res.latitude
  148. // const longitude = res.longitude
  149. // state.position = {
  150. // latitude,
  151. // longitude
  152. // }
  153. // console.log(res);
  154. // }
  155. // })
  156. },
  157. logout(state){
  158. uni.showModal({
  159. title: '确认退出登录吗',
  160. success(r) {
  161. if(r.confirm){
  162. state.userInfo = {}
  163. state.shop = false
  164. uni.removeStorageSync('token')
  165. uni.redirectTo({
  166. url: '/pages/index/index'
  167. })
  168. }
  169. }
  170. })
  171. },
  172. },
  173. actions: {},
  174. })
  175. export default store