index.js 7.6 KB

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