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