index.vue 10 KB

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