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

146 lines
3.1 KiB

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