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

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