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

261 lines
5.4 KiB

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