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

262 lines
5.5 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
6 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 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. // 当前分区景点
  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. categoryId : n.categoryId,
  51. width: 20, //图标icon 宽度
  52. height: 28 ,//图标icon 高度
  53. iconPath: `/static/image/tourGuide/${n.categoryId}.png`, //图标
  54. id: index,
  55. callout: { //自定义标记点上方的气泡窗口 点击有效
  56. content: n.spotName, //文本
  57. color: '#000', //文字颜色
  58. fontSize: 13, //文本大小
  59. borderRadius: 13, //边框圆角
  60. padding: '10',
  61. bgColor: '#fff', //背景颜色
  62. display: 'ALWAYS', //隐藏
  63. },
  64. })
  65. })
  66. return list
  67. },
  68. },
  69. mutations: {
  70. // 初始化配置
  71. initConfig(state){
  72. // api('getConfig', res => {
  73. // if(res.code == 200){
  74. // state.configList = res.result
  75. // }
  76. // })
  77. let config = ['getPrivacyPolicy', 'getUserAgreement']
  78. config.forEach(k => {
  79. api(k, res => {
  80. if (res.code == 200) {
  81. state.configList[k] = res.result
  82. }
  83. })
  84. })
  85. },
  86. // 设置气泡显示与隐藏
  87. setDisplay(state, id){
  88. state.spotList.forEach((n, index) => {
  89. if(n.id == id){
  90. // 显示气泡
  91. n.display = 'ALWAYS'
  92. }else{
  93. // 隐藏气泡
  94. n.display = 'BYCLICK'
  95. }
  96. })
  97. },
  98. // 导览页面设置当前选择的菜单,0-景点 1-美食店铺 2-民宿 3-厕所
  99. setSpotGuideIndex(state, index){
  100. state.spotGuideIndex = index
  101. },
  102. setAreaId(state, areaId){
  103. state.areaId = areaId
  104. },
  105. // 获取所有页面的轮播图
  106. getBanner(state){
  107. // 0-首页 1-遗产路径 2-我要跟拍 3-非遗体验 4-无忧服务 5申遗历程 6-遗产概况
  108. let config = ['path', 'follow', 'experience', 'service', 'course', 'yc']
  109. config.forEach((k, i) => {
  110. api('queryBannerList', {
  111. bannerCategoryType : i + 1,
  112. }, res => {
  113. if(res.code == 200){
  114. state.banner[k] = res.result
  115. }
  116. })
  117. })
  118. },
  119. getSpotList(state){
  120. api('querySpotList', {
  121. pageNo : 1,
  122. pageSize : 999999999,
  123. }, res => {
  124. if(res.code == 200){
  125. let spot = []
  126. res.result.records.forEach(n => {
  127. if(n.spotLatitude && n.spotLongitude){
  128. n.distance = 0
  129. n.display = 'BYCLICK'
  130. spot.push(n)
  131. }
  132. })
  133. Position.calculateDistance()
  134. state.spotList = spot
  135. this.commit('calculateDistance')
  136. }
  137. })
  138. },
  139. // 计算地点与自己的距离
  140. calculateDistance(state){
  141. if(state.spotList.length && state.position.latitude){
  142. state.spotList.forEach(n => {
  143. n.distance = parseFloat(Position.calculateDistance(
  144. state.position.latitude,
  145. state.position.longitude,
  146. n.spotLatitude,
  147. n.spotLongitude,
  148. 3
  149. ))
  150. })
  151. // 排序,最近的在前面
  152. state.spotList.sort((a, b) => a.distance - b.distance)
  153. }
  154. },
  155. // 查询购物车
  156. getCartList(state){
  157. api('queryShopcarList', {
  158. pageNo : 1,
  159. pageSize : 999999999,
  160. }, res => {
  161. if(res.code == 200){
  162. state.cartCheckboxValue = []
  163. res.result.forEach(n => {
  164. state.cartCheckboxValue.push(n.shopcar.id)
  165. })
  166. state.cartList = res.result
  167. }
  168. })
  169. },
  170. login(state){
  171. uni.showLoading({
  172. title: '登录中...'
  173. })
  174. uni.login({
  175. success(res) {
  176. if(res.errMsg != "login:ok"){
  177. return
  178. }
  179. api('wxLogin', {
  180. code : res.code,
  181. latitude : state.position.latitude,
  182. longitude : state.position.longitude,
  183. }, res => {
  184. uni.hideLoading()
  185. if(res.code != 200){
  186. return
  187. }
  188. state.userInfo = res.result.userInfo
  189. uni.setStorageSync('token', res.result.token)
  190. if(!state.userInfo.nickName || !state.userInfo.headImage){
  191. uni.navigateTo({
  192. url: '/pages_order/auth/wxUserInfo'
  193. })
  194. }else{
  195. uni.navigateBack(-1)
  196. }
  197. })
  198. }
  199. })
  200. },
  201. getUserInfo(state){
  202. api('getInfo', res => {
  203. if(res.code == 200){
  204. state.userInfo = res.result
  205. }
  206. })
  207. },
  208. logout(state){
  209. uni.showModal({
  210. title: '确认退出登录吗',
  211. success(r) {
  212. if(r.confirm){
  213. uni.removeStorageSync('token')
  214. uni.redirectTo({
  215. url: '/pages/index/index'
  216. })
  217. }
  218. }
  219. })
  220. },
  221. getPosition(state){
  222. Position.getLocation(res => {
  223. state.position = res
  224. this.commit('calculateDistance')
  225. })
  226. },
  227. },
  228. actions: {},
  229. })
  230. export default store