微信

index.vue 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div class="mainPage" v-if="showPage">
  3. <div class="banner flex-h">
  4. <div class="flex-item">
  5. <div>
  6. <div>
  7. <swiper :options="swiperOption" ref="mySwiper">
  8. <swiper-slide class="swiper-slide" v-for="(item,index) in banner" :key="index">
  9. <img :src="item.ImageUrl" class="cover" alt @click="jump(item)">
  10. </swiper-slide>
  11. </swiper>
  12. </div>
  13. </div>
  14. </div>
  15. </div>
  16. <div class="subNav">
  17. <ul class="flex-h">
  18. <router-link
  19. tag="li"
  20. class="flex-item"
  21. v-for="(item, index) in fiveA"
  22. :to="{name:'fiveA',query:{id:item.LocationId}}"
  23. :key="index"
  24. >
  25. <img :src="item.TypeImg" alt>
  26. <span>{{item.LocationName}}</span>
  27. </router-link>
  28. </ul>
  29. </div>
  30. <div class="areaHeader flex-h">
  31. <h1 class="flex-item">探索·发现</h1>
  32. <router-link v-if="project.length>5" :to="{name: 'majorProjectsList'}">查看所有</router-link>
  33. </div>
  34. <div class="areaContent">
  35. <div class="scroll-h find">
  36. <div>
  37. <swiper :options="swiperHOption" ref="mySwiperH">
  38. <swiper-slide
  39. class="swiper-slide"
  40. v-for="(item,index) in ProjectWithLocationList"
  41. v-if="index<5"
  42. :key="index"
  43. >
  44. <router-link
  45. tag="div"
  46. :to="{ name:'majorProjects', query:{ id: item.CmsCaseId } }"
  47. style="width:100%;height:100%;position:relative;"
  48. >
  49. <img :src="getImg(item.CmsCaseImgs)" class="cover" alt>
  50. <span v-if="item.CaseId!='all'">
  51. <i class="iconfont icon-dingwei"></i>
  52. {{item.jl}}
  53. </span>
  54. </router-link>
  55. </swiper-slide>
  56. </swiper>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="areaHeader flex-h" v-if="courseList.length>0">
  61. <h1 class="flex-item">近期课程</h1>
  62. <router-link v-show="courseList.length>5" :to="{name: 'courseList'}">查看所有</router-link>
  63. </div>
  64. <div class="areaContent" v-if="courseList.length>0">
  65. <div class="scroll-h course">
  66. <div>
  67. <swiper :options="swiperHOption" ref="mySwiperH">
  68. <swiper-slide
  69. class="swiper-slide"
  70. v-for="(item,index) in courseList"
  71. :key="index"
  72. v-if="index<5"
  73. >
  74. <router-link
  75. tag="div"
  76. :to="{ name:'majorProjectsDetail', query:{ id: item.CourseId } }"
  77. style="width:100%;position:relative;overflow:visible"
  78. >
  79. <div class="img">
  80. <img :src="item.CourseImg" class="cover centerLabel" alt>
  81. <span>{{item.CourseName}}</span>
  82. </div>
  83. <div class="price">
  84. <span>¥{{item.Price}}</span>
  85. </div>
  86. <span>{{`${toolClass.dateFormat(item.BeginDate,'yyyy.MM.dd')}~${toolClass.dateFormat(item.EndDate,'MM.dd')}`}}</span>
  87. <span>{{item.CaseName}}</span>
  88. </router-link>
  89. </swiper-slide>
  90. </swiper>
  91. </div>
  92. </div>
  93. </div>
  94. <div class="areaHeader flex-h">
  95. <h1 class="flex-item">活动资讯</h1>
  96. </div>
  97. <div class="areaContent newsList flex-h">
  98. <div class="flex-item">
  99. <div>
  100. <ul>
  101. <li
  102. class="flex-h"
  103. v-for="(item,index) in newsList"
  104. :key="index"
  105. @click="jump(item)"
  106. v-if="index<5"
  107. >
  108. <a class="img">
  109. <img :src="item.ImageUrl" class="centerLabel cover" alt>
  110. </a>
  111. <div class="flex-item">
  112. <div>
  113. <span>{{item.Title}}</span>
  114. <span>{{toolClass.dateFormat(item.CreateDate)}}</span>
  115. </div>
  116. </div>
  117. </li>
  118. </ul>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </template>
  124. <script>
  125. import { swiper, swiperSlide } from 'vue-awesome-swiper'
  126. import 'swiper/dist/css/swiper.css'
  127. import toolClass from '../../../../util/util'
  128. import { mapState, createNamespacedHelpers } from 'vuex'
  129. import wx from 'weixin-jsapi'
  130. const { mapState: mapIndexState, mapActions: mapIndexActions } = createNamespacedHelpers('index')
  131. // const wx = require('weixin-js-sdk')
  132. import wxsdk from '@/util/share'
  133. export default {
  134. name: '',
  135. data () {
  136. return {
  137. swiperOption: {
  138. observer: true,
  139. loop: true,
  140. speed: 400,
  141. autoplay: {
  142. disableOnInteraction: false,
  143. }
  144. },
  145. swiperHOption: {
  146. observer: true,
  147. freeMode: true,
  148. slidesPerView: 'auto',
  149. },
  150. newsList: [],
  151. showPage: false
  152. }
  153. },
  154. computed: {
  155. ...mapState({
  156. orgid: x => x.app.orgId,
  157. fiveA: x => x.index.fiveA,
  158. banner: x => x.index.banner,
  159. message: x => x.index.message,
  160. project: x => x.index.project,
  161. cms: x => x.index.cms,
  162. longitude1: x => x.index.longitude1,
  163. latitude1: x => x.index.latitude1
  164. }),
  165. ...mapIndexState({
  166. courseList: x => x.courseList
  167. }),
  168. MySwiper () {
  169. return this.$refs.mySwiper.swiper
  170. },
  171. MySwiperH () {
  172. return this.$refs.mySwiperH.swiper
  173. },
  174. ProjectWithLocationList () {
  175. var data = this.project || []
  176. if (this.latitude1 === 0 && this.longitude1 === 0) {
  177. data.forEach((item) => {
  178. item.jl = '未获取到当前定位'
  179. })
  180. return data
  181. } else {
  182. let arr = []
  183. let dataNew = []
  184. data.forEach((item) => {
  185. if (item.Coordinate) {
  186. item.jl = parseInt(toolClass.getGreatCircleDistance(this.latitude1, this.longitude1, item.Coordinate.split(',')[0], item.Coordinate.split(',')[1]))
  187. arr.push({ jl: item.jl, CmsCaseId: item.CmsCaseId })
  188. } else {
  189. item.jl = 400000000
  190. arr.push({ jl: item.jl, CmsCaseId: item.CmsCaseId })
  191. }
  192. })
  193. arr.sort((a, b) => { return a.jl - b.jl })
  194. arr.forEach((curr) => {
  195. data.forEach((item) => {
  196. if (curr.CmsCaseId === item.CmsCaseId && item.jl === curr.jl) {
  197. item.jl = `距离${item.jl}米`
  198. dataNew.push(item)
  199. }
  200. })
  201. })
  202. return dataNew
  203. }
  204. }
  205. },
  206. components: {
  207. swiper,
  208. swiperSlide
  209. },
  210. created () {
  211. let that = this
  212. wxsdk({ url: encodeURIComponent(window.location.href.split('#')[0]) }, {
  213. title: '城的空间',
  214. desc: '城的空间',
  215. link: `${window.location.origin}${window.location.pathname}#/mainPage/indexPage`,
  216. thu_image: `https://spaceofcheng.oss-cn-beijing.aliyuncs.com/indexlogo.jpg?x-oss-process=style/wxicon`
  217. }).then(() => {
  218. wx.getLocation({
  219. type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  220. success: function (res) {
  221. that.setLocation({ latitude1: res.latitude, longitude1: res.longitude })
  222. },
  223. })
  224. })
  225. that.showPage = true
  226. that.init()
  227. },
  228. methods: {
  229. ...mapIndexActions(['getIndexLocation', 'getIndexInfo', 'getCourseList', 'setLocation']),
  230. jump (item) {
  231. item.ForwardType = item.ForwardType || ''
  232. if (item.ForwardType === 'url') {
  233. window.location.href = item.ForwardUrl
  234. return
  235. } else if (item.ForwardType === 'course') {
  236. if (item.ForwardResourceId) {
  237. this.$router.push({ name: 'majorProjectsDetail', query: { id: item.ForwardResourceId } }) // 此处去课程详情
  238. return
  239. } else {
  240. this.$router.push({ name: 'majorProjectsDetail', query: { id: item.ForwardCourseId } }) // 此处去课程详情
  241. return
  242. }
  243. } else {
  244. window.location.href = item.InfoUrl
  245. return
  246. }
  247. },
  248. getImg (list) {
  249. return list.filter(item => item.ImageType === 'cover')[0].CaseImageUrl
  250. },
  251. init () {
  252. this.getIndexLocation({ orgid: this.orgid, issys: '0' }).then((res) => {
  253. // this.data.fiveA = this.fiveA
  254. this.locationId = 'index'
  255. this.getIndexInfo({ orgid: this.orgid, locationid: this.locationId }).then((res) => {
  256. this.newsList = this.cms
  257. if (this.project !== undefined && this.project !== null) {
  258. for (let i = 0; i < this.project.length; i++) {
  259. if (this.project[i].CmsCaseImgs != null) {
  260. for (let j = 0; j < this.project[i].CmsCaseImgs.length; j++) {
  261. if (this.project[i].CmsCaseImgs[j].ImageType === 'cover') {
  262. this.project[i].CaseImageUrl = this.project[i].CmsCaseImgs[j].CaseImageUrl
  263. }
  264. }
  265. }
  266. }
  267. }
  268. })
  269. this.getCourseList({
  270. pagesize: 10000,
  271. page: 1
  272. }).then(() => {
  273. this.showPage = true
  274. })
  275. })
  276. }
  277. }
  278. }
  279. </script>
  280. <!-- Add "scoped" attribute to limit CSS to this component only -->
  281. <style lang="scss" scoped>
  282. @import 'page.scss';
  283. </style>