加油站付款小程序,打印小票
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.

126 lines
2.5 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 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. //Vuex.Store 构造器选项
  6. const store = new Vuex.Store({
  7. state: {
  8. configList: {
  9. phone: "",
  10. preferential: 1,
  11. price: 6.66,
  12. privacyAgreement: "隐私政策",
  13. title: "#95",
  14. userAgreement: "用户协议",
  15. wx: "",
  16. }, //配置对象
  17. userInfo : {},
  18. gasStationList : [],
  19. gasStation : {},
  20. },
  21. getters: {
  22. getConfig(state){
  23. return state.configList
  24. }
  25. },
  26. mutations: {
  27. // 初始化配置
  28. initConfig(state) {
  29. // let config = ['preferential', 'wx', 'phone', 'price', 'title']
  30. // config.forEach(k => {
  31. // api('getConfig', {
  32. // keyValue : k
  33. // }, res => {
  34. // if (res.code == 200) {
  35. // state.configList[k] = res.result
  36. // }
  37. // })
  38. // })
  39. let apiConfig = [ 'getPrivacyPolicy' , 'getUserAgreement' ] //需要访问不同接口才能得到的配置数据
  40. let key = ['privacyAgreement','userAgreement']
  41. apiConfig.forEach((item,index) => {
  42. api(item,res => {
  43. state.configList[key[index]] = res.result
  44. })
  45. })
  46. },
  47. twogetConfig(state){
  48. api('twogetConfig', {
  49. shopId : state.gasStation.id
  50. }, res => {
  51. if (res.code == 200) {
  52. ['preferential', 'wx', 'phone', 'price', 'title']
  53. .forEach(n => {
  54. state.configList[n] = res.result[n]
  55. })
  56. }
  57. })
  58. },
  59. //获取加油站列表
  60. getGasStationList(state){
  61. api('getGasStationList', {
  62. pageNo : 1,
  63. pageSize : 9999999
  64. }, res => {
  65. if(res.code == 200){
  66. state.gasStationList = res.result.records
  67. }
  68. })
  69. },
  70. setGasStation(state, data){
  71. state.gasStation = data
  72. this.commit('twogetConfig')
  73. },
  74. login(state) {
  75. uni.showLoading({
  76. title:"登录中..."
  77. })
  78. uni.login({
  79. success(res) {
  80. if (res.errMsg != "login:ok") {
  81. return
  82. }
  83. api('loginLogin', {
  84. code: res.code
  85. }, res => {
  86. uni.hideLoading()
  87. if (res.code != 200) {
  88. return
  89. }
  90. state.userInfo = res.result.userInfo
  91. uni.setStorageSync('token', res.result.token)
  92. if (!state.userInfo.nickName || !state.userInfo.headImage) {
  93. uni.navigateTo({
  94. url: '/pages/login/wxUserInfo'
  95. })
  96. }else{
  97. uni.switchTab({
  98. url: '/pages/payment/payment'
  99. })
  100. }
  101. })
  102. },
  103. fail(err) {
  104. console.error(err)
  105. uni.hideLoading()
  106. }
  107. })
  108. },
  109. getUserInfo(state) {
  110. api('infoGetInfo', res => {
  111. if(res.code == 200){
  112. state.userInfo = res.result
  113. }
  114. })
  115. },
  116. },
  117. actions: {},
  118. })
  119. export default store