景徳镇旅游微信小程序
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.

210 lines
4.3 KiB

9 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 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. import Position from '@/utils/position.js'
  6. //Vuex.Store 构造器选项
  7. const store = new Vuex.Store({
  8. state: {
  9. configList: [], //配置列表
  10. position : {//定位信息
  11. latitude : 0,
  12. longitude : 0,
  13. },
  14. userInfo : {},//用户信息
  15. cartList : [//购物车列表
  16. {
  17. id : 1,
  18. title : '桌布租赁',
  19. num : 1,
  20. price : 299,
  21. unit : '120*40*75【桌子尺寸】',
  22. },
  23. {
  24. id : 2,
  25. title : '桌布租赁',
  26. num : 1,
  27. price : 299,
  28. unit : '120*40*75【桌子尺寸】',
  29. },//购物车列表
  30. ],
  31. banner : {},
  32. cartCheckboxValue : [],//选中的购物车
  33. spotList : [],//所有的地点
  34. spotGuideIndex : 0,//导览页面当前选择标签
  35. areaId : 0,//景区id
  36. },
  37. getters: {
  38. spotGuide(state){
  39. return state.spotList.filter(n => {
  40. let i = state.spotGuideIndex < 2 ?
  41. 0 : state.spotGuideIndex - 1
  42. console.log(i);
  43. if(i != n.categoryId){
  44. return false
  45. }
  46. return true
  47. })
  48. },
  49. spotGuideMarkers(state){
  50. let list = []
  51. state.spotList.forEach(n => {
  52. list.push({
  53. latitude: n.spotLatitude,
  54. longitude: n.spotLongitude,
  55. width: 20, //图标icon 宽度
  56. height: 28 ,//图标icon 高度
  57. iconPath: `/static/image/tourGuide/${n.categoryId}.png`, //图标
  58. id: n.id,
  59. })
  60. })
  61. return list
  62. },
  63. },
  64. mutations: {
  65. // 初始化配置
  66. initConfig(state){
  67. // api('getConfig', res => {
  68. // if(res.code == 200){
  69. // state.configList = res.result
  70. // }
  71. // })
  72. let config = ['getPrivacyPolicy', 'getUserAgreement']
  73. config.forEach(k => {
  74. api(k, res => {
  75. if (res.code == 200) {
  76. state.configList[k] = res.result
  77. }
  78. })
  79. })
  80. },
  81. // 导览页面设置当前选择的菜单,0-景点 1-美食店铺 2-民宿 3-厕所
  82. setSpotGuideIndex(state, index){
  83. state.spotGuideIndex = index
  84. },
  85. // 获取所有页面的轮播图
  86. getBanner(state){
  87. // 0-首页 1-遗产路径 2-我要跟拍 3-非遗体验 4-无忧服务 5申遗历程
  88. let config = ['path', 'follow', 'experience', 'service', 'course']
  89. config.forEach((k, i) => {
  90. api('queryBannerList', {
  91. bannerCategoryType : i + 1,
  92. }, res => {
  93. if(res.code == 200){
  94. state.banner[k] = res.result
  95. }
  96. })
  97. })
  98. },
  99. getSpotList(state){
  100. api('querySpotList', {
  101. pageNo : 1,
  102. pageSize : 999999999,
  103. }, res => {
  104. if(res.code == 200){
  105. let spot = []
  106. res.result.records.forEach(n => {
  107. if(n.spotLatitude && n.spotLongitude){
  108. n.distance = 0,
  109. spot.push(n)
  110. }
  111. })
  112. Position.calculateDistance()
  113. state.spotList = spot
  114. this.commit('calculateDistance')
  115. }
  116. })
  117. },
  118. // 计算地点与自己的距离
  119. calculateDistance(state){
  120. if(state.spotList.length && state.position.latitude){
  121. state.spotList.forEach(n => {
  122. n.distance = parseFloat(Position.calculateDistance(
  123. state.position.latitude,
  124. state.position.longitude,
  125. n.spotLatitude,
  126. n.spotLongitude,
  127. 3
  128. ))
  129. })
  130. // 排序,最近的在前面
  131. state.spotList.sort((a, b) => a.distance - b.distance)
  132. console.log(state.spotList);
  133. }
  134. },
  135. login(state){
  136. uni.showLoading({
  137. title: '登录中...'
  138. })
  139. uni.login({
  140. success(res) {
  141. if(res.errMsg != "login:ok"){
  142. return
  143. }
  144. api('wxLogin', {
  145. code : res.code,
  146. latitude : state.position.latitude,
  147. longitude : state.position.longitude,
  148. }, res => {
  149. uni.hideLoading()
  150. if(res.code != 200){
  151. return
  152. }
  153. state.userInfo = res.result.userInfo
  154. uni.setStorageSync('token', res.result.token)
  155. // if(!state.userInfo.nickName || !state.userInfo.headImage){
  156. // uni.navigateTo({
  157. // url: '/pages_order/auth/wxUserInfo'
  158. // })
  159. // }else{
  160. uni.navigateBack(-1)
  161. // }
  162. })
  163. }
  164. })
  165. },
  166. getUserInfo(state){
  167. api('infoGetInfo', res => {
  168. if(res.code == 200){
  169. state.userInfo = res.result
  170. }
  171. })
  172. },
  173. getPosition(state){
  174. Position.getLocation(res => {
  175. state.position = res
  176. this.commit('calculateDistance')
  177. })
  178. },
  179. },
  180. actions: {},
  181. })
  182. export default store