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

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