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

271 lines
5.7 KiB

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