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

268 lines
5.7 KiB

10 months ago
10 months 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
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. res.result.forEach(n => {
  75. state.configList[n.paramCode] = n.paramValueText ||
  76. n.paramValueTextarea ||
  77. n.paramValueImage
  78. // state.configList[n.keyName + '_keyValue'] = n.keyValue
  79. })
  80. uni.$emit('getConfig', state)
  81. }
  82. })
  83. let config = ['getPrivacyPolicy', 'getUserAgreement']
  84. config.forEach(k => {
  85. api(k, res => {
  86. if (res.code == 200) {
  87. state.configList[k] = res.result
  88. }
  89. })
  90. })
  91. },
  92. // 设置气泡显示与隐藏
  93. setDisplay(state, id){
  94. state.spotList.forEach((n, index) => {
  95. if(n.id == id){
  96. // 显示气泡
  97. n.display = 'ALWAYS'
  98. }else{
  99. // 隐藏气泡
  100. n.display = 'BYCLICK'
  101. }
  102. })
  103. },
  104. // 导览页面设置当前选择的菜单,0-景点 1-美食店铺 2-民宿 3-厕所
  105. setSpotGuideIndex(state, index){
  106. state.spotGuideIndex = index
  107. },
  108. setAreaId(state, areaId){
  109. state.areaId = areaId
  110. },
  111. // 获取所有页面的轮播图
  112. getBanner(state){
  113. // 0-首页 1-遗产路径 2-我要跟拍 3-非遗体验 4-无忧服务 5申遗历程 6-遗产概况
  114. let config = ['path', 'follow', 'experience', 'service', 'course', 'yc']
  115. config.forEach((k, i) => {
  116. api('queryBannerList', {
  117. bannerCategoryType : i + 1,
  118. }, res => {
  119. if(res.code == 200){
  120. state.banner[k] = res.result
  121. }
  122. })
  123. })
  124. },
  125. getSpotList(state){
  126. api('querySpotList', {
  127. pageNo : 1,
  128. pageSize : 999999999,
  129. }, res => {
  130. if(res.code == 200){
  131. let spot = []
  132. res.result.records.forEach(n => {
  133. if(n.spotLatitude && n.spotLongitude){
  134. n.distance = 0
  135. n.display = 'BYCLICK'
  136. spot.push(n)
  137. }
  138. })
  139. Position.calculateDistance()
  140. state.spotList = spot
  141. this.commit('calculateDistance')
  142. }
  143. })
  144. },
  145. // 计算地点与自己的距离
  146. calculateDistance(state){
  147. if(state.spotList.length && state.position.latitude){
  148. state.spotList.forEach(n => {
  149. n.distance = parseFloat(Position.calculateDistance(
  150. state.position.latitude,
  151. state.position.longitude,
  152. n.spotLatitude,
  153. n.spotLongitude,
  154. 3
  155. ))
  156. })
  157. // 排序,最近的在前面
  158. state.spotList.sort((a, b) => a.distance - b.distance)
  159. }
  160. },
  161. // 查询购物车
  162. getCartList(state){
  163. api('queryShopcarList', {
  164. pageNo : 1,
  165. pageSize : 999999999,
  166. }, res => {
  167. if(res.code == 200){
  168. state.cartCheckboxValue = []
  169. res.result.forEach(n => {
  170. state.cartCheckboxValue.push(n.shopcar.id)
  171. })
  172. state.cartList = res.result
  173. }
  174. })
  175. },
  176. login(state){
  177. uni.showLoading({
  178. title: '登录中...'
  179. })
  180. uni.login({
  181. success(res) {
  182. if(res.errMsg != "login:ok"){
  183. return
  184. }
  185. api('wxLogin', {
  186. code : res.code,
  187. latitude : state.position.latitude,
  188. longitude : state.position.longitude,
  189. }, res => {
  190. uni.hideLoading()
  191. if(res.code != 200){
  192. return
  193. }
  194. state.userInfo = res.result.userInfo
  195. uni.setStorageSync('token', res.result.token)
  196. if(!state.userInfo.nickName || !state.userInfo.headImage){
  197. uni.navigateTo({
  198. url: '/pages_order/auth/wxUserInfo'
  199. })
  200. }else{
  201. uni.navigateBack(-1)
  202. }
  203. })
  204. }
  205. })
  206. },
  207. getUserInfo(state){
  208. api('getInfo', res => {
  209. if(res.code == 200){
  210. state.userInfo = res.result
  211. }
  212. })
  213. },
  214. logout(state){
  215. uni.showModal({
  216. title: '确认退出登录吗',
  217. success(r) {
  218. if(r.confirm){
  219. uni.removeStorageSync('token')
  220. uni.redirectTo({
  221. url: '/pages/index/index'
  222. })
  223. }
  224. }
  225. })
  226. },
  227. getPosition(state){
  228. Position.getLocation(res => {
  229. state.position = res
  230. this.commit('calculateDistance')
  231. })
  232. },
  233. },
  234. actions: {},
  235. })
  236. export default store