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

127 lines
2.6 KiB

6 months ago
5 months ago
6 months ago
5 months ago
6 months ago
6 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
5 months ago
6 months ago
5 months ago
6 months ago
6 months ago
5 months ago
6 months ago
5 months ago
6 months ago
5 months ago
5 months ago
6 months ago
6 months ago
5 months ago
6 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. },
  18. getters: {
  19. // 角色 true 为供应商 false 为采购商
  20. userShop(state){
  21. return state.shop
  22. },
  23. userInfo(state){
  24. return state.userInfo
  25. },
  26. },
  27. mutations: {
  28. // 初始化配置
  29. initConfig(state){
  30. // api('getConfig', res => {
  31. // if(res.code == 200){
  32. // state.configList = res.result
  33. // }
  34. // })
  35. let config = ['getPrivacyPolicy', 'getUserAgreement']
  36. config.forEach(k => {
  37. api(k, res => {
  38. if (res.code == 200) {
  39. state.configList[k] = res.result
  40. }
  41. })
  42. })
  43. },
  44. login(state, form){
  45. uni.showLoading({
  46. title: '登录中...'
  47. })
  48. api('loginUser', form, res => {
  49. uni.hideLoading()
  50. if(res.code != 200){
  51. return
  52. }
  53. state.userInfo = res.result.userInfo
  54. state.buy = res.result.buy
  55. state.shopData = res.result.shop
  56. state.shop = !!res.result.shop
  57. uni.setStorageSync('token', res.result.token)
  58. if(!state.shopData && !state.buy){
  59. uni.reLaunch({
  60. url: '/pages_order/auth/selectionIdentity?back=no&'
  61. })
  62. }else{
  63. uni.reLaunch({
  64. url: '/pages/index/index'
  65. })
  66. }
  67. })
  68. },
  69. // 获取个人信息
  70. getUserInfo(state){
  71. api('getImagePhoneOther', res => {
  72. if(res.code == 200){
  73. state.userInfo = res.result.my
  74. state.customerPhone = res.result.phone
  75. state.buy = res.result.buy
  76. state.shopData = res.result.shop
  77. // 如果什么身份都没有,就去注册
  78. if(!state.shopData && !state.buy){
  79. uni.reLaunch({
  80. url: '/pages_order/auth/selectionIdentity?back=no&'
  81. })
  82. }
  83. // 没有供应商身份
  84. if(!state.shopData){
  85. state.shop = false
  86. // 没有采购商身份
  87. }else if(!state.buy){
  88. state.shop = true
  89. }
  90. }
  91. })
  92. },
  93. logout(state){
  94. uni.showModal({
  95. title: '确认退出登录吗',
  96. success(r) {
  97. if(r.confirm){
  98. state.userInfo = {}
  99. state.role = false
  100. uni.removeStorageSync('token')
  101. uni.redirectTo({
  102. url: '/pages/index/index'
  103. })
  104. }
  105. }
  106. })
  107. },
  108. setShop(state, date){
  109. state.shop = date
  110. },
  111. },
  112. actions: {},
  113. })
  114. export default store