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

238 lines
4.8 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
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. banner : {},
  17. cartCheckboxValue : [],//选中的购物车
  18. spotList : [],//所有的地点
  19. spotGuideIndex : 0,//导览页面当前选择标签
  20. areaId : 0,//景区id
  21. },
  22. getters: {
  23. spotGuide(state){
  24. return state.spotList.filter(n => {
  25. // let i = state.spotGuideIndex < 2 ?
  26. // 0 : state.spotGuideIndex - 1
  27. if(state.spotGuideIndex != n.categoryId){
  28. return false
  29. }
  30. if(state.areaId != n.areaId){
  31. return false
  32. }
  33. return true
  34. })
  35. },
  36. spotGuideMarkers(state){
  37. let list = []
  38. state.spotList.forEach((n, index) => {
  39. if(state.spotGuideIndex != n.categoryId){
  40. return
  41. }
  42. if(state.areaId != n.areaId){
  43. return
  44. }
  45. list.push({
  46. latitude: n.spotLatitude,
  47. longitude: n.spotLongitude,
  48. width: 20, //图标icon 宽度
  49. height: 28 ,//图标icon 高度
  50. iconPath: `/static/image/tourGuide/${n.categoryId}.png`, //图标
  51. id: index,
  52. })
  53. })
  54. return list
  55. },
  56. },
  57. mutations: {
  58. // 初始化配置
  59. initConfig(state){
  60. // api('getConfig', res => {
  61. // if(res.code == 200){
  62. // state.configList = res.result
  63. // }
  64. // })
  65. let config = ['getPrivacyPolicy', 'getUserAgreement']
  66. config.forEach(k => {
  67. api(k, res => {
  68. if (res.code == 200) {
  69. state.configList[k] = res.result
  70. }
  71. })
  72. })
  73. },
  74. // 导览页面设置当前选择的菜单,0-景点 1-美食店铺 2-民宿 3-厕所
  75. setSpotGuideIndex(state, index){
  76. state.spotGuideIndex = index
  77. },
  78. setAreaId(state, areaId){
  79. state.areaId = areaId
  80. },
  81. // 获取所有页面的轮播图
  82. getBanner(state){
  83. // 0-首页 1-遗产路径 2-我要跟拍 3-非遗体验 4-无忧服务 5申遗历程
  84. let config = ['path', 'follow', 'experience', 'service', 'course']
  85. config.forEach((k, i) => {
  86. api('queryBannerList', {
  87. bannerCategoryType : i + 1,
  88. }, res => {
  89. if(res.code == 200){
  90. state.banner[k] = res.result
  91. }
  92. })
  93. })
  94. },
  95. getSpotList(state){
  96. api('querySpotList', {
  97. pageNo : 1,
  98. pageSize : 999999999,
  99. }, res => {
  100. if(res.code == 200){
  101. let spot = []
  102. res.result.records.forEach(n => {
  103. if(n.spotLatitude && n.spotLongitude){
  104. n.distance = 0
  105. spot.push(n)
  106. }
  107. })
  108. Position.calculateDistance()
  109. state.spotList = spot
  110. this.commit('calculateDistance')
  111. }
  112. })
  113. },
  114. // 计算地点与自己的距离
  115. calculateDistance(state){
  116. if(state.spotList.length && state.position.latitude){
  117. state.spotList.forEach(n => {
  118. n.distance = parseFloat(Position.calculateDistance(
  119. state.position.latitude,
  120. state.position.longitude,
  121. n.spotLatitude,
  122. n.spotLongitude,
  123. 3
  124. ))
  125. })
  126. // 排序,最近的在前面
  127. state.spotList.sort((a, b) => a.distance - b.distance)
  128. console.log(state.spotList);
  129. }
  130. },
  131. // 查询购物车
  132. getCartList(state){
  133. api('queryShopcarList', {
  134. pageNo : 1,
  135. pageSize : 999999999,
  136. }, res => {
  137. if(res.code == 200){
  138. state.cartCheckboxValue = []
  139. res.result.forEach(n => {
  140. state.cartCheckboxValue.push(n.shopcar.id)
  141. })
  142. state.cartList = res.result
  143. }
  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('getInfo', res => {
  179. if(res.code == 200){
  180. state.userInfo = res.result
  181. }
  182. })
  183. },
  184. logout(state){
  185. uni.showModal({
  186. title: '确认退出登录吗',
  187. success(r) {
  188. if(r.confirm){
  189. uni.removeStorageSync('token')
  190. uni.redirectTo({
  191. url: '/pages/index/index'
  192. })
  193. }
  194. }
  195. })
  196. },
  197. getPosition(state){
  198. Position.getLocation(res => {
  199. state.position = res
  200. this.commit('calculateDistance')
  201. })
  202. },
  203. },
  204. actions: {},
  205. })
  206. export default store