铝交易,微信公众号
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.

133 lines
2.8 KiB

9 months ago
8 months ago
9 months ago
8 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
8 months ago
9 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
8 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 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
8 months ago
9 months ago
8 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 { date } from '../uni_modules/uv-ui-tools/libs/function/test';
  6. //Vuex.Store 构造器选项
  7. const store = new Vuex.Store({
  8. state: {
  9. configList: {}, //配置列表
  10. shop : true,
  11. userInfo : {}, //用户信息
  12. shopData : {},
  13. buy : {},
  14. customerPhone : '',//客服电话
  15. productDetail : {},//商品详情用于中转
  16. cartInfo : {},//采购商下单的时候供应商开户行信息
  17. pic : '',//清关服务图片
  18. },
  19. getters: {
  20. // 角色 true 为供应商 false 为采购商
  21. userShop(state){
  22. return state.shop
  23. },
  24. userInfo(state){
  25. return state.userInfo
  26. },
  27. },
  28. mutations: {
  29. // 初始化配置
  30. initConfig(state){
  31. api('getConfig', res => {
  32. if(res.code == 200){
  33. // state.configList = res.result
  34. res.result.forEach(n => {
  35. state.configList[n.name] = n
  36. })
  37. }
  38. })
  39. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  40. // config.forEach(k => {
  41. // api(k, res => {
  42. // if (res.code == 200) {
  43. // state.configList[k] = res.result
  44. // }
  45. // })
  46. // })
  47. },
  48. login(state, form){
  49. uni.showLoading({
  50. title: '登录中...'
  51. })
  52. api('loginUser', form, res => {
  53. uni.hideLoading()
  54. if(res.code != 200){
  55. return
  56. }
  57. state.userInfo = res.result.userInfo
  58. state.buy = res.result.buy
  59. state.shopData = res.result.shop
  60. state.shop = !!res.result.shop
  61. uni.setStorageSync('token', res.result.token)
  62. if(!state.shopData && !state.buy){
  63. uni.reLaunch({
  64. url: '/pages_order/auth/selectionIdentity?back=no&'
  65. })
  66. }else{
  67. uni.reLaunch({
  68. url: '/pages/index/index'
  69. })
  70. }
  71. })
  72. },
  73. // 获取个人信息
  74. getUserInfo(state){
  75. api('getImagePhoneOther', res => {
  76. if(res.code == 200){
  77. state.userInfo = res.result.my
  78. state.customerPhone = res.result.phone
  79. state.buy = res.result.buy
  80. state.shopData = res.result.shop
  81. state.pic = res.result.pic
  82. // 如果什么身份都没有,就去注册
  83. if(!state.shopData && !state.buy){
  84. uni.reLaunch({
  85. url: '/pages_order/auth/selectionIdentity?back=no&'
  86. })
  87. }
  88. // 没有供应商身份
  89. if(!state.shopData){
  90. state.shop = false
  91. // 没有采购商身份
  92. }else if(!state.buy){
  93. state.shop = true
  94. }
  95. }
  96. })
  97. },
  98. logout(state){
  99. uni.showModal({
  100. title: '确认退出登录吗',
  101. success(r) {
  102. if(r.confirm){
  103. state.userInfo = {}
  104. state.role = false
  105. uni.removeStorageSync('token')
  106. uni.redirectTo({
  107. url: '/pages/index/index'
  108. })
  109. }
  110. }
  111. })
  112. },
  113. setShop(state, date){
  114. state.shop = date
  115. },
  116. },
  117. actions: {},
  118. })
  119. export default store