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

239 lines
4.8 KiB

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