index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <template>
  2. <view class="content">
  3. <view class="content_top">
  4. <u-navbar leftText="" height="44px" :bgColor="bgColor" :placeholder="true">
  5. <view class="navbar_left hflex acenter" slot="left">
  6. <image src="../../../static/images/index/logo.png" style="width: 160rpx;height: 60rpx;"></image>
  7. <view class="dian" v-if="city != '全国'"></view>
  8. <view class="hflex acenter" v-if="city && city != '全国'">
  9. <image :src="weather.icon" style="width: 32rpx;height: 32rpx;margin-right: 8rpx;"></image>
  10. <view class="text_style1">{{weather.min}}&deg;~{{weather.max}}&deg;</view>
  11. </view>
  12. </view>
  13. </u-navbar>
  14. <view class="search hflex acenter" :class="scrollHeight > 0 ? 'bg_white' : ''">
  15. <view class="hflex acenter" @click="changeCity">
  16. <view class="city">{{city ? city : '全国'}}</view>
  17. <u-icon name="arrow-down-fill" color="#000" size="10"></u-icon>
  18. </view>
  19. <u-search v-model="serach_value" borderColor="#506dff" placeholder="搜索关键词" shape="round" :showAction="false"
  20. @click="focus" disabled bgColor="#fff">
  21. </u-search>
  22. </view>
  23. </view>
  24. <view class="swiper">
  25. <u-swiper :indicator="true" indicatorActiveColor="#506dff" :list="bannerList" radius="20rpx" @click="toBanner" keyName="img" height="170"></u-swiper>
  26. </view>
  27. <view class="notice hflex acenter jbetween">
  28. <!-- <view class="notice_left">公告</view> -->
  29. <u-notice-bar :text="notice_text" direction="column" icon="公告" color="#7a7b7c" bgColor="#f3f7ff" @click="toNot"></u-notice-bar>
  30. <view class="hflex acenter" @click="toNotlist">
  31. <view class="text1">更多</view>
  32. <u-icon name="arrow-right" color="#bebebf" size="14"></u-icon>
  33. </view>
  34. </view>
  35. <view class="boxs hflex acenter jbetween">
  36. <image :src="class_img1" mode="widthFix" style="width: 336rpx;" @click="toDetail(1)"></image>
  37. <image :src="class_img2" mode="widthFix" style="width: 336rpx;" @click="toDetail(2)"></image>
  38. </view>
  39. <view class="boxs hflex acenter jbetween">
  40. <image :src="class_img3" mode="widthFix" style="width: 220rpx;" @click="toDetail(3)"></image>
  41. <image :src="class_img4" mode="widthFix" style="width: 220rpx;" @click="toDetail(4)"></image>
  42. <image :src="class_img5" mode="widthFix" style="width: 220rpx;" @click="toDetail(5)"></image>
  43. </view>
  44. <view class="boxs fixed" :style="'top:' + height + 'px'">
  45. <u-tabs :list="tabs" @click="changeTaaba" :scrollable = "true"
  46. :activeStyle="{
  47. fontSize: '30rpx',
  48. color: '#000',
  49. }" :inactiveStyle="{
  50. fontSize: '30rpx',
  51. color: '#888888'
  52. }"></u-tabs>
  53. </view>
  54. <view class="boxs" style="margin: 0;" v-if="pageList.length > 0">
  55. <news-module :pageList="pageList" @toDetail="toNews"></news-module>
  56. </view>
  57. <!-- <view class="boxs" v-else>
  58. <u-empty icon="https://ship.shipcc.cn/common/zhan.png" text="暂时没有数据哦">
  59. </view> -->
  60. </view>
  61. </template>
  62. <script>
  63. import $api, { closeLoading } from '@/static/js/api.js'
  64. var that = ''
  65. const app = getApp().globalData
  66. export default {
  67. data() {
  68. return {
  69. title: 'Hello',
  70. weather: {
  71. icon: '/static/icons/100.svg',
  72. min: 0,
  73. max: 10
  74. },
  75. city: '',
  76. location: '',
  77. serach_value: '',
  78. bannerList: [
  79. ],
  80. notice_text: [
  81. ],
  82. noticeList: [],
  83. class_img1: 'https://cn-shanghai-aliyun-cloudauth-1196126035163283.oss-cn-shanghai.aliyuncs.com/class_img1.png',
  84. class_img2: 'https://cn-shanghai-aliyun-cloudauth-1196126035163283.oss-cn-shanghai.aliyuncs.com/class_img2.png',
  85. class_img3: 'https://cn-shanghai-aliyun-cloudauth-1196126035163283.oss-cn-shanghai.aliyuncs.com/class_img3.png',
  86. class_img4: 'https://cn-shanghai-aliyun-cloudauth-1196126035163283.oss-cn-shanghai.aliyuncs.com/class_img4.png',
  87. class_img5: 'https://cn-shanghai-aliyun-cloudauth-1196126035163283.oss-cn-shanghai.aliyuncs.com/class_img5.png',
  88. tabs: [],
  89. pageList: [
  90. ],
  91. bgColor: 'rgb(255,255,255,0)',
  92. exad: '',
  93. page: 1,
  94. total: 1,
  95. cid: '',
  96. scrollHeight: 0,
  97. height: 0
  98. }
  99. },
  100. onLoad() {
  101. that = this
  102. let res = uni.getSystemInfoSync()
  103. that.height = res.statusBarHeight + 92
  104. console.log('getSystemInfoSync',res);
  105. // this.getCity()
  106. // that.getCate()
  107. // that.getBanner()
  108. // that.HXlogin()
  109. },
  110. onShow() {
  111. that.exad = []
  112. that.getCity()
  113. that.getCate()
  114. that.getNotice()
  115. that.getBanner()
  116. },
  117. onPullDownRefresh() {
  118. that.getNotice()
  119. },
  120. watch: {
  121. city(newVal, oldVal) {
  122. console.log('城市数据发生改变');
  123. that.getCity()
  124. }
  125. },
  126. onPageScroll(e) {
  127. that.scrollHeight = e.scrollTop
  128. if(e.scrollTop != 0) {
  129. that.bgColor = "#fff"
  130. } else {
  131. that.bgColor = 'rgba(255,255,255,0)'
  132. }
  133. },
  134. methods: {
  135. getBanner() {
  136. $api.req({
  137. url: '/data/api.Data/getSlider',
  138. data: {
  139. keys: 'home_banner'
  140. }
  141. }, function(res) {
  142. if(res.code == 1) {
  143. that.bannerList = res.data
  144. }
  145. })
  146. },
  147. getNotice() {
  148. $api.req({
  149. url: '/data/api.Notice/index',
  150. data: {
  151. page: 1,
  152. limit: 10
  153. }
  154. }, function(res) {
  155. if(res.code == 1) {
  156. that.noticeList = res.data.data
  157. for(var i=0;i<that.noticeList.length;i++) {
  158. that.notice_text.push(that.noticeList[i].title)
  159. }
  160. // uni.stopPullDownRefresh();
  161. }
  162. uni.stopPullDownRefresh();
  163. })
  164. },
  165. // 获取当前位置
  166. getCity() {
  167. that.city = uni.getStorageSync('city') ? uni.getStorageSync('city') : '全国'
  168. console.log(that.city);
  169. if(!that.city) {
  170. // that.city = '全国'
  171. return new Promise((resolve, reject) => {
  172. app.getLoca().then(res=> {
  173. console.log('getLoaction',res);
  174. that.city = res[0].regeocodeData.addressComponent.city
  175. uni.setStorageSync('city',that.city)
  176. uni.setStorageSync('locationCity',that.city)
  177. })
  178. })
  179. }
  180. that.getWeather()
  181. },
  182. changeCity() {
  183. $api.jump('/page_index/pages/index/changeCity')
  184. },
  185. // 获取当前城市天气
  186. getWeather() {
  187. if(that.city == '全国') {
  188. return
  189. }
  190. uni.request({
  191. url: 'https://geoapi.qweather.com/v2/city/lookup',
  192. data: {
  193. key: '682de67f4b8d4a5e97bc63ed722ae3cf',
  194. location:that.city
  195. },
  196. header:{
  197. 'content-type': 'application/x-www-form-urlencoded',
  198. },
  199. success(res) {
  200. uni.request({
  201. url: "https://devapi.qweather.com/v7/weather/7d",
  202. data: {
  203. location: res.data.location[0].id,
  204. key: '682de67f4b8d4a5e97bc63ed722ae3cf'
  205. },
  206. header:{
  207. 'content-type': 'application/x-www-form-urlencoded',
  208. },
  209. success(res2) {
  210. that.weather = {
  211. icon: '/static/icons/' + res2.data.daily[0].iconDay + '.svg',
  212. min: res2.data.daily[0].tempMin,
  213. max: res2.data.daily[0].tempMax
  214. }
  215. }
  216. })
  217. }
  218. })
  219. /* $api.req({
  220. url: '/data/api.Weather/area',
  221. data: {
  222. name: that.city
  223. }
  224. }, function(res) {
  225. that.weather = {
  226. icon: '/static/icons/' + res.data.daily[0].iconDay + '.svg',
  227. min: res.data.daily[0].tempMin,
  228. max: res.data.daily[0].tempMax
  229. }
  230. }) */
  231. },
  232. // 点击天气
  233. toWeather() {
  234. // $api.jump('/page_index/pages/index/weather')
  235. },
  236. // 轮播图跳转
  237. toBanner(e) {
  238. var url = that.bannerList[e].url
  239. if(url == '#') {
  240. return
  241. }
  242. $api.jump('/pages/user/web_view?src=' + encodeURIComponent(url))
  243. },
  244. // 点击输入框
  245. focus() {
  246. $api.jump('/page_index/pages/index/search')
  247. },
  248. toNot(index) {
  249. $api.jump('/page_index/pages/index/noticeDetail?id=' + that.noticeList[index].id)
  250. },
  251. // 公告列表
  252. toNotlist() {
  253. $api.jump('/page_index/pages/index/noticeList')
  254. },
  255. toDetail(index) {
  256. var url = ''
  257. switch(index) {
  258. case 1:
  259. url = '/page_index/pages/demand/demand';
  260. break;
  261. case 2:
  262. url = '/page_index/pages/purchase/purchase';
  263. break;
  264. case 3:
  265. url = '/page_index/pages/repair/repair';
  266. break;
  267. case 4:
  268. url = '/page_index/pages/bidding/bidding';
  269. break;
  270. case 5:
  271. url = '/page_index/pages/resources/resources';
  272. break;
  273. }
  274. $api.jump(url)
  275. },
  276. // 切换tabs
  277. changeTaaba(e) {
  278. that.page = 1
  279. that.cid = e.id
  280. // that.pageList = []
  281. that.exad = []
  282. that.getList(that.cid)
  283. },
  284. getCate() {
  285. $api.req({
  286. url: '/data/api.Xw/category'
  287. }, function(res) {
  288. if(res.code == 1) {
  289. that.tabs = res.data
  290. that.cid = that.tabs[0].id
  291. that.getList(that.cid)
  292. }
  293. })
  294. },
  295. getList(cid) {
  296. $api.req({
  297. url: '/data/api.Xw/index',
  298. data: {
  299. page: that.page,
  300. cid: cid,
  301. keyword: that.serach_value,
  302. exad: that.exad
  303. }
  304. }, function(res) {
  305. if(res.code == 1) {
  306. for(var i=0;i<res.data.data.length;i++) {
  307. if(res.data.data[i].images == "") {
  308. that.$set(res.data.data[i],'has_img',true)
  309. }else {
  310. res.data.data[i].images = res.data.data[i].images.split('|')
  311. }
  312. if(res.data.data[i].ctype == 2) {
  313. that.exad += res.data.data[i].id+ ','
  314. }
  315. }
  316. if(that.page == 1) {
  317. that.pageList = res.data.data
  318. } else {
  319. that.pageList = that.pageList.concat(res.data.data)
  320. }
  321. that.total = res.data.total
  322. // that.exad = res.data.exad.join(',')
  323. }
  324. })
  325. },
  326. toNews(index) {
  327. if(that.pageList[index].ctype == 1) {
  328. $api.jump('/page_index/pages/index/newDetail?id=' + that.pageList[index].id)
  329. } else if(that.pageList[index].ctype == 2){
  330. $api.jump('/page_index/pages/index/ggDetail?id=' + that.pageList[index].id)
  331. }
  332. },
  333. onReachBottom() {
  334. if (Number(that.page) * 15 >= Number(that.total)) {
  335. $api.info("没有更多了")
  336. } else {
  337. that.page++
  338. that.getList(that.cid)
  339. }
  340. }
  341. }
  342. }
  343. </script>
  344. <style lang="scss" scoped>
  345. .content::v-deep {
  346. // padding: 0 30rpx;
  347. background: #fff;
  348. .content_top {
  349. position: relative;
  350. background: url('../../../static/images/index/bg.png') no-repeat;
  351. background-size: 100%;
  352. box-sizing: border-box;
  353. padding: 0 30rpx 120rpx;
  354. .navbar_left {
  355. .dian {
  356. width: 8rpx;
  357. height: 8rpx;
  358. background: #232323;
  359. border-radius: 50%;
  360. margin: 0 6rpx 0 12rpx;
  361. }
  362. }
  363. .search {
  364. position: fixed;
  365. width: 691rpx;
  366. box-sizing: border-box;
  367. z-index: 999;
  368. padding: 20rpx 0;
  369. /* margin-top: 36rpx; */
  370. .city {
  371. color: #222222;
  372. font-size: 32rpx;
  373. margin-right: 16rpx;
  374. }
  375. .u-input {
  376. border: solid 1rpx #526eff;
  377. background: #fff;
  378. height: 76rpx;
  379. margin-left: 16rpx;
  380. padding: 0 24rpx !important;
  381. }
  382. }
  383. }
  384. .swiper {
  385. width: 690rpx;
  386. // box-sizing: border-box;
  387. // padding: 0 30rpx;
  388. height: 170px;
  389. margin: 0rpx auto 20rpx;
  390. border-radius: 20rpx;
  391. .u-swiper__wrapper__item__wrapper {
  392. height: 170px;
  393. }
  394. }
  395. .notice {
  396. width: 690rpx;
  397. box-sizing: border-box;
  398. padding: 15rpx 30rpx 15rpx 0;
  399. background-color: #f3f7ff;
  400. margin: 0 30rpx 0;
  401. border-radius: 20rpx;
  402. .u-notice-bar {
  403. // background-color: #f3f7ff !important;
  404. //
  405. .u-icon__icon {
  406. font-size: 32rpx;
  407. // padding-left: 24rpx;
  408. color: #506dff !important;
  409. padding-right: 20rpx;
  410. border-right: 3rpx solid #f1f1f1;
  411. }
  412. }
  413. .notice_left {
  414. }
  415. }
  416. // .class_img {
  417. // width: 100%;
  418. // box-sizing: border-box;
  419. // padding: 0 30rpx;
  420. // }
  421. .boxs {
  422. width: 100%;
  423. box-sizing: border-box;
  424. padding: 0 30rpx;
  425. margin: 24rpx 0 0;
  426. }
  427. .fixed {
  428. background-color: #fff;
  429. position: sticky;
  430. top: 256rpx;
  431. z-index: 99;
  432. }
  433. .bg_white {
  434. background-color: #fff !important;
  435. }
  436. .text1 {
  437. font-size: 25rpx;
  438. color: #8f8f90;
  439. }
  440. }
  441. </style>