index.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import api from '../common/config/caimeiApi.js'
  4. import authorize from '../common/config/authorize.js'
  5. import * as caimeiApi from '@/common/config/caimeiApi.js'
  6. import ajaxService from '@/services/ajax.service.js'
  7. import UserService from '@/services/user.service.js'
  8. import SellerService from '@/services/sellse.service.js'
  9. const getUserService = new UserService(ajaxService)
  10. const getSellerService = new SellerService(ajaxService)
  11. Vue.use(Vuex)
  12. const store = new Vuex.Store({
  13. state: {
  14. isWxAuthorize: false,
  15. hasLogin: false,
  16. userInfo: {},
  17. identity: 0,
  18. noticeNum:0,
  19. couponEntry:0, // 活动状态
  20. clubType: 0, // 1: 医美机构 2:生美机构 (医美、生美机构类型)
  21. wechatUserInfo: {},
  22. cartNumber: 0,
  23. isIphoneX: false,
  24. isActivity: false, // 首页活动弹窗
  25. isLoginType: 0,
  26. isLoginProductId: 0,
  27. isManage: false,// 是否是管理员或者小组长
  28. shopAdvert:[] // 供应商广告图列表
  29. },
  30. mutations: {
  31. login(state, provider) { //用户身份 1、协销 2、资质机构 3、供应商 4.个人机构
  32. state.hasLogin = true
  33. state.userInfo = provider
  34. uni.setStorage({ //缓存用户登陆状态
  35. key: 'userInfo',
  36. data: provider
  37. })
  38. },
  39. logout(state) {
  40. state.hasLogin = false
  41. state.userInfo = {}
  42. uni.removeStorage({
  43. key: 'userInfo'
  44. })
  45. uni.removeStorage({
  46. key: 'token'
  47. })
  48. },
  49. wxLogin(state, provider) {
  50. state.isWxAuthorize = true
  51. state.wechatUserInfo = provider
  52. uni.setStorage({ //缓存用户登陆状态
  53. key: 'wechatUserInfo',
  54. data: provider
  55. })
  56. uni.setStorageSync('_WX_State', 1)
  57. },
  58. updateStatus(state, provider) {
  59. let TIME = api.formatDate()
  60. console.log(`${TIME}`, provider)
  61. state.userInfo = provider
  62. if (state.userInfo) {
  63. state.clubType = provider.firstClubType
  64. state.identity = provider.userIdentity
  65. // 判断登录用户为协销 设置管理员组长权限
  66. if(provider.userIdentity === 1){
  67. if(provider.manager>0 || provider.leaderId > 0){
  68. state.isManage = true
  69. }
  70. }
  71. // 判断以下公司账户设置部分权限
  72. if (provider.userId == 5261 || provider.userId == 10947 || provider.userId == 11579) {
  73. state.identity = 1
  74. } else if (provider.firstClubType == 1) {
  75. state.identity = 5
  76. } else {
  77. state.identity = 0
  78. }
  79. }
  80. uni.setStorage({ //缓存用户登陆状态
  81. key: 'userInfo',
  82. data: provider
  83. })
  84. },
  85. async updateNoticeNum(state) { // 更新通知消息数量
  86. try{
  87. const userInfo = await caimeiApi.getStorage()
  88. const commonId = userInfo.clubId ? userInfo.clubId : 0
  89. const res = await getUserService.getAuthClubCount({ commonId: commonId })
  90. state.noticeNum = res.data.count
  91. if (state.noticeNum >= 100) {
  92. uni.setTabBarBadge({
  93. index: 2,
  94. text: '99+'
  95. })
  96. } else if (state.noticeNum > 0) {
  97. uni.setTabBarBadge({
  98. index: 2,
  99. text: String(state.noticeNum)
  100. })
  101. } else {
  102. uni.removeTabBarBadge({
  103. index: 2,
  104. })
  105. }
  106. }catch(error){
  107. uni.removeTabBarBadge({
  108. index: 2,
  109. })
  110. }
  111. },
  112. // async updateSellerNoticeNum(state) { // 更新协销通知消息数量
  113. // const userInfo = await caimeiApi.getStorage()
  114. // const commonId = userInfo.serviceProviderId ? userInfo.serviceProviderId : 0
  115. // console.log(userInfo, commonId)
  116. // getSellerService.getSellerNoticeSpCount({ commonId: commonId, messageType: 3 })
  117. // .then(response => {
  118. // state.noticeNum = response.data.notificationCount
  119. // console.log(response)
  120. // if (state.noticeNum >= 100) {
  121. // uni.setTabBarBadge({
  122. // index: 2,
  123. // text: '99+'
  124. // })
  125. // } else if (state.noticeNum > 0) {
  126. // uni.setTabBarBadge({
  127. // index: 2,
  128. // text: String(state.noticeNum)
  129. // })
  130. // } else {
  131. // uni.removeTabBarBadge({
  132. // index: 2,
  133. // })
  134. // }
  135. // })
  136. // .catch(error => {
  137. // uni.removeTabBarBadge({
  138. // index: 2,
  139. // })
  140. // })
  141. // },
  142. async updateRossShow(state){
  143. const USER_EVEN = await caimeiApi.getStorage()
  144. if(USER_EVEN.userIdentity === 1) { return }
  145. try{
  146. const res = await getUserService.getShopAdvert({ userId: USER_EVEN.userId ? USER_EVEN.userId : 0 })
  147. state.shopAdvert = res.data
  148. }catch(error){
  149. console.log(error)
  150. }
  151. },
  152. updateAllNum(state, num) {
  153. if (num >= 100) {
  154. uni.setTabBarBadge({
  155. index: 3,
  156. text: '99+'
  157. })
  158. } else if (num > 0) {
  159. uni.setTabBarBadge({
  160. index: 3,
  161. text: String(num)
  162. })
  163. } else {
  164. uni.removeTabBarBadge({
  165. index: 3,
  166. })
  167. }
  168. },
  169. updateCouponEntry(state, couponEntry){// 记录是否有优惠券
  170. state.couponEntry = couponEntry
  171. },
  172. setActivity(state, variable) { // 记录活动弹窗状态
  173. state.isActivity = variable
  174. },
  175. setChangeVar(state, variable) {
  176. state.isIphoneX = variable
  177. },
  178. setIsIphone(state, variable) { // 记录设备信息是否为IphoneX
  179. state.isIphone = variable
  180. },
  181. setLoginType(state, variable) { // 记录登录跳转类型
  182. state.isLoginType = variable
  183. console.log(state.isLoginType)
  184. },
  185. setLoginProductId(state, variable) { // 记录跳转商品ID
  186. state.isLoginProductId = variable
  187. console.log(state.isLoginProductId)
  188. },
  189. setLoginOrderId(state, variable) { // 记录跳转订单ID
  190. state.isLoginOrderId = variable
  191. console.log(state.isLoginOrderId)
  192. }
  193. },
  194. actions: {
  195. setVariableFun: function(context, vData) {
  196. context.commit('setChangeVar', vData)
  197. },
  198. setIsIphoneFun: function(context, vData) {
  199. context.commit('setIsIphone', vData)
  200. },
  201. setActivityFn: function(context, vData) {
  202. context.commit('setActivity', vData)
  203. },
  204. // setLoginTypeFn:function(context,vData){
  205. // context.commit('setLoginType',vData)
  206. // }
  207. }
  208. })
  209. export default store