index.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. isRossShow:false // 是否显示ross广告图
  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. const userInfo = await caimeiApi.getStorage()
  87. const commonId = userInfo.clubId ? userInfo.clubId : 0
  88. getUserService.getAuthClubCount({ commonId: commonId })
  89. .then(response => {
  90. state.noticeNum = response.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. })
  107. .catch(error => {
  108. uni.removeTabBarBadge({
  109. index: 2,
  110. })
  111. })
  112. },
  113. async updateSellerNoticeNum(state) { // 更新协销通知消息数量
  114. const userInfo = await caimeiApi.getStorage()
  115. const commonId = userInfo.serviceProviderId ? userInfo.serviceProviderId : 0
  116. console.log(userInfo, commonId)
  117. getSellerService.getSellerNoticeSpCount({ commonId: commonId, messageType: 3 })
  118. .then(response => {
  119. state.noticeNum = response.data.accountCount
  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. getUserService.userInformationVisitRoos({ userId: USER_EVEN.userId ? USER_EVEN.userId : 0 })
  146. .then(response => {
  147. state.isRossShow = response.data
  148. })
  149. .catch(error => {
  150. console.log(error)
  151. })
  152. },
  153. updateAllNum(state, num) {
  154. if (num >= 100) {
  155. uni.setTabBarBadge({
  156. index: 3,
  157. text: '99+'
  158. })
  159. } else if (num > 0) {
  160. uni.setTabBarBadge({
  161. index: 3,
  162. text: String(num)
  163. })
  164. } else {
  165. uni.removeTabBarBadge({
  166. index: 3,
  167. })
  168. }
  169. },
  170. updateCouponEntry(state, couponEntry){// 记录是否有优惠券
  171. state.couponEntry = couponEntry
  172. },
  173. setActivity(state, variable) { // 记录活动弹窗状态
  174. state.isActivity = variable
  175. },
  176. setChangeVar(state, variable) {
  177. state.isIphoneX = variable
  178. },
  179. setIsIphone(state, variable) { // 记录设备信息是否为IphoneX
  180. state.isIphone = variable
  181. },
  182. setLoginType(state, variable) { // 记录登录跳转类型
  183. state.isLoginType = variable
  184. console.log(state.isLoginType)
  185. },
  186. setLoginProductId(state, variable) { // 记录跳转商品ID
  187. state.isLoginProductId = variable
  188. console.log(state.isLoginProductId)
  189. },
  190. setLoginOrderId(state, variable) { // 记录跳转订单ID
  191. state.isLoginOrderId = variable
  192. console.log(state.isLoginOrderId)
  193. }
  194. },
  195. actions: {
  196. setVariableFun: function(context, vData) {
  197. context.commit('setChangeVar', vData)
  198. },
  199. setIsIphoneFun: function(context, vData) {
  200. context.commit('setIsIphone', vData)
  201. },
  202. setActivityFn: function(context, vData) {
  203. context.commit('setActivity', vData)
  204. },
  205. // setLoginTypeFn:function(context,vData){
  206. // context.commit('setLoginType',vData)
  207. // }
  208. }
  209. })
  210. export default store