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

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
3 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. setGasStationList(state, data){
  75. state.gasStationList = data
  76. },
  77. login(state) {
  78. uni.showLoading({
  79. title:"登录中..."
  80. })
  81. uni.login({
  82. success(res) {
  83. if (res.errMsg != "login:ok") {
  84. return
  85. }
  86. api('loginLogin', {
  87. code: res.code
  88. }, res => {
  89. uni.hideLoading()
  90. if (res.code != 200) {
  91. return
  92. }
  93. state.userInfo = res.result.userInfo
  94. uni.setStorageSync('token', res.result.token)
  95. if (!state.userInfo.nickName || !state.userInfo.headImage) {
  96. uni.navigateTo({
  97. url: '/pages/login/wxUserInfo'
  98. })
  99. }else{
  100. uni.switchTab({
  101. url: '/pages/payment/payment'
  102. })
  103. }
  104. })
  105. },
  106. fail(err) {
  107. console.error(err)
  108. uni.hideLoading()
  109. }
  110. })
  111. },
  112. getUserInfo(state) {
  113. api('infoGetInfo', res => {
  114. if(res.code == 200){
  115. state.userInfo = res.result
  116. }
  117. })
  118. },
  119. },
  120. actions: {},
  121. })
  122. export default store