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

216 lines
4.4 KiB

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