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

138 lines
2.9 KiB

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