酒店桌布为微信小程序
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.

195 lines
3.9 KiB

9 months ago
9 months ago
9 months ago
7 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
7 months ago
9 months ago
7 months ago
9 months ago
7 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
8 months ago
9 months ago
9 months ago
7 months ago
9 months ago
8 months ago
7 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('getConfigOne', res => {
  30. // if(res.code == 200){
  31. // state.configList = res.result
  32. // }
  33. // })
  34. let config = ['privacyXieYi', 'depositPrice']
  35. config.forEach(k => {
  36. api('getConfigOne', {
  37. name : k
  38. },res => {
  39. if (res.code == 200) {
  40. state.configList[k] = res.result
  41. }
  42. })
  43. })
  44. },
  45. //获取绑定店铺的数据
  46. getBindShop(state){
  47. api('bindShop', res => {
  48. if(res.code == 200){
  49. state.bindShop = res.result
  50. }
  51. })
  52. },
  53. // 水洗店查询首页统计
  54. getLaundryStoreHomeData(state){
  55. api('laundryStoreHomeData', {}, res => {
  56. uni.stopPullDownRefresh()
  57. if(res.code == 200){
  58. state.statistics = res.result
  59. }
  60. })
  61. },
  62. // 获取分类
  63. categoryList(state){
  64. api('categoryList', res => {
  65. if(res.code == 200){
  66. state.category = res.result
  67. }
  68. })
  69. },
  70. // 账号密码登录
  71. accountLogin(state, form){
  72. api('wxLogin', {
  73. latitude : state.position.latitude,
  74. longitude : state.position.longitude,
  75. loginType : 1,
  76. ...form,
  77. }, res => {
  78. if(res.code == 200){
  79. uni.setStorageSync('token', res.result.token)
  80. state.userInfo = res.result.userInfo
  81. state.shop = true
  82. uni.redirectTo({
  83. url: '/pages/index/index'
  84. })
  85. }
  86. })
  87. },
  88. login(state){
  89. let self = this
  90. uni.showLoading({
  91. title: '登录中...'
  92. })
  93. uni.login({
  94. success(res) {
  95. if(res.errMsg != "login:ok"){
  96. return
  97. }
  98. api('wxLogin', {
  99. code : res.code,
  100. latitude : state.position.latitude,
  101. longitude : state.position.longitude,
  102. loginType : 0,
  103. }, res => {
  104. uni.hideLoading()
  105. if(res.code != 200){
  106. return
  107. }
  108. state.userInfo = res.result.userInfo
  109. // state.shop = !!state.userInfo.shop
  110. uni.setStorageSync('token', res.result.token)
  111. self.commit('getUserInfo')
  112. if(!state.userInfo.nickName || !state.userInfo.headImage){
  113. uni.navigateTo({
  114. url: '/pages_order/auth/wxUserInfo'
  115. })
  116. }else{
  117. uni.navigateBack(-1)
  118. }
  119. })
  120. }
  121. })
  122. },
  123. getUserInfo(state){
  124. api('getInfo', res => {
  125. if(res.code == 200){
  126. state.userInfo = res.result
  127. state.shop = !!state.userInfo.shop
  128. if(state.shop){
  129. // 查询水洗店首页统计
  130. this.commit('getLaundryStoreHomeData')
  131. }else{
  132. //获取绑定店铺的数据
  133. this.commit('getBindShop')
  134. }
  135. }
  136. })
  137. },
  138. getPosition(state){
  139. Position.getLocation(res => {
  140. console.log(res);
  141. state.position = res
  142. })
  143. // console.log('wx.getFuzzyLocation');
  144. // uni.getFuzzyLocation({
  145. // type: 'wgs84',
  146. // isHighAccuracy: true,
  147. // highAccuracyExpireTime: 1000,
  148. // success (res) {
  149. // const latitude = res.latitude
  150. // const longitude = res.longitude
  151. // state.position = {
  152. // latitude,
  153. // longitude
  154. // }
  155. // console.log(res);
  156. // }
  157. // })
  158. },
  159. logout(state){
  160. uni.showModal({
  161. title: '确认退出登录吗',
  162. success(r) {
  163. if(r.confirm){
  164. state.userInfo = {}
  165. state.shop = false
  166. state.bindShop = {}
  167. uni.removeStorageSync('token')
  168. uni.redirectTo({
  169. url: '/pages/index/index'
  170. })
  171. }
  172. }
  173. })
  174. },
  175. },
  176. actions: {},
  177. })
  178. export default store