shipyard.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view class="content">
  3. <view class="search">
  4. <u-input v-model="serach_value" type="text" :border="true" placeholder="输入搜索关键词" shape="circle"
  5. prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399" @confirm="search">
  6. <template slot="suffix">
  7. <view @click="search">搜索</view>
  8. </template>
  9. </u-input>
  10. </view>
  11. <view class="swiper">
  12. <u-swiper :list="bannerList" radius="20rpx" @click="toBanner" keyName="img" height="160"></u-swiper>
  13. </view>
  14. <view class="box">
  15. <view class="tabs hflex acenter jbetween">
  16. <block v-for="(item,index) in tabs" :key="index">
  17. <view class="tabs_item" :class="active == item.id ? 'active' : ''" @click="changeTabs(item.id)">{{item.name}}</view>
  18. </block>
  19. </view>
  20. <view class="list" v-if="pageList.length > 0">
  21. <block v-for="(item,index) in pageList" :key="index">
  22. <view class="list_item hflex acenter jbetween" @click="toDetail(item.id)">
  23. <image :src="item.head_img" class="item_img" mode="aspectFill"></image>
  24. <view class="item_right vflex jbetween">
  25. <view class="hflex acenter jbetween">
  26. <view class="name">{{item.name}}</view>
  27. <view class="shipyard">{{item.pos}}</view>
  28. </view>
  29. <view class="address">{{item.address}}</view>
  30. </view>
  31. </view>
  32. </block>
  33. </view>
  34. <!-- <view v-else>
  35. <u-empty icon="https://ship.shipcc.cn/common/zhan.png" text="暂时没有数据哦">
  36. </view> -->
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import $api from '@/static/js/api.js'
  42. var that = ''
  43. export default {
  44. data() {
  45. return {
  46. serach_value: '',
  47. bannerList: [
  48. ],
  49. tabs: [
  50. {
  51. id: 1,
  52. name: '综合推荐'
  53. },
  54. {
  55. id: 2,
  56. name: '距离'
  57. }
  58. ],
  59. active: 1,
  60. pageList: [
  61. ],
  62. page: 1,
  63. limit: 10,
  64. total: 1,
  65. token: '',
  66. }
  67. },
  68. onLoad() {
  69. that = this
  70. that.getBanner()
  71. that.token = uni.getStorageSync('token')
  72. },
  73. onShow() {
  74. that.getList()
  75. },
  76. onPullDownRefresh() {
  77. var token = uni.getStorageSync('token')
  78. console.log(token);
  79. if(!token) {
  80. $api.jump('/pages/login/password_login')
  81. }
  82. that.getList()
  83. },
  84. methods: {
  85. getBanner() {
  86. $api.req({
  87. url: '/data/api.Data/getSlider',
  88. data: {
  89. keys: 'data_shipyard'
  90. }
  91. }, function(res) {
  92. if(res.code == 1) {
  93. that.bannerList = res.data
  94. }
  95. })
  96. },
  97. // banner图跳转
  98. toBanner(e) {
  99. var url = that.bannerList[e].url
  100. if(url == '#') {
  101. return
  102. }
  103. $api.jump('/pages/user/web_view?src=' +url)
  104. },
  105. getList() {
  106. $api.req({
  107. url: '/data/api.ShipYard/index',
  108. data: {
  109. sort: that.active,
  110. keyword: that.serach_value,
  111. longitude: uni.getStorageSync('userLocation').split(',')[0],
  112. latitude: uni.getStorageSync('userLocation').split(',')[1],
  113. page: that.page
  114. }
  115. }, function(res) {
  116. if(res.code == 1) {
  117. if(that.page == 1) {
  118. that.pageList = res.data.data
  119. } else {
  120. that.pageList = that.pageList.concat(res.data.data)
  121. }
  122. that.total = res.data.total
  123. that.limit = res.data.per_page
  124. }else if (res.code == 401) {
  125. $api.info("请先登录")
  126. setTimeout(() => {
  127. $api.jump('/pages/login/password_login')
  128. },1000)
  129. }
  130. uni.stopPullDownRefresh();
  131. })
  132. },
  133. // 切换tabs
  134. changeTabs(id) {
  135. that.active = id
  136. that.page = 1
  137. that.pageList = []
  138. that.getList()
  139. },
  140. toDetail(id) {
  141. if(!that.token) {
  142. $api.jump('/pages/login/password_login')
  143. } else {
  144. $api.jump('/pages/tabbar/shipyard/detail?id=' + id)
  145. }
  146. },
  147. search() {
  148. that.getList()
  149. // $api.jump('/pages/tabbar/shipyard/news?value=' + that.serach_value)
  150. },
  151. onReachBottom() {
  152. if (Number(that.page) * Number(that.limit) >= Number(that.total)) {
  153. $api.info("没有更多了")
  154. } else {
  155. that.page++
  156. that.getList()
  157. }
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .content::v-deep {
  164. background-color: #f6f6f6;
  165. .search {
  166. position: fixed;
  167. z-index: 999;
  168. background: #fff;
  169. width: 100%;
  170. height: 88rpx;
  171. box-sizing: border-box;
  172. padding: 12rpx 30rpx;
  173. .u-input {
  174. background-color: #fff;
  175. height: 64rpx;
  176. padding: 0 0 0 18rpx !important;
  177. border: 1rpx solid #506Dff;
  178. margin-bottom: 12rpx;
  179. }
  180. .u-input__content__subfix-icon {
  181. width: 128rpx;
  182. height: 64rpx;
  183. background-color: #506Dff;
  184. border-radius: 32rpx;
  185. color: #fff;
  186. font-size: 28rpx;
  187. text-align: center;
  188. line-height: 64rpx;
  189. }
  190. }
  191. .swiper {
  192. width: 100%;
  193. margin-top: 108rpx;
  194. box-sizing: border-box;
  195. padding: 0 30rpx;
  196. }
  197. .box {
  198. width: 690rpx;
  199. margin: 20rpx 30rpx 0;
  200. background: #fff;
  201. border-radius: 20rpx;
  202. box-sizing: border-box;
  203. padding: 24rpx 20rpx;
  204. .tabs {
  205. width: 100%;
  206. .tabs_item {
  207. width: 312rpx;
  208. height: 56rpx;
  209. background-color: #f6f6f6;
  210. border-radius: 8rpx;
  211. font-size: 28rpx;
  212. color: #444;
  213. text-align: center;
  214. line-height: 56rpx;
  215. }
  216. .active {
  217. background-color: #f1f3ff;
  218. color: #506dff;
  219. }
  220. }
  221. .list {
  222. .list_item {
  223. width: 100%;
  224. height: 152rpx;
  225. box-sizing: border-box;
  226. padding: 24rpx 0;
  227. border-bottom: 1rpx solid #f6f6f6;
  228. .item_img {
  229. width: 104rpx;
  230. height: 104rpx;
  231. border-radius: 16rpx;
  232. margin-right: 20rpx;
  233. }
  234. .item_right {
  235. width: calc(100% - 124rpx);
  236. height: 100%;
  237. .name {
  238. width: 80%;
  239. color: #333;
  240. font-size: 28rpx;
  241. overflow: hidden;
  242. white-space: nowrap;
  243. text-overflow: ellipsis;
  244. }
  245. .shipyard{
  246. width: auto;
  247. height: 28rpx;
  248. background-color: #506dff;
  249. border-radius: 5rpx;
  250. font-size: 16rpx;
  251. color: #fff;
  252. text-align: center;
  253. line-height: 28rpx;
  254. padding: 0 8rpx;
  255. box-sizing: border-box;
  256. }
  257. }
  258. .address {
  259. font-size: 20rpx;
  260. color: #666;
  261. padding-bottom: 20rpx;
  262. }
  263. }
  264. .list_item:nth-last-child(1) {
  265. padding-bottom: 0;
  266. border: none;
  267. }
  268. }
  269. }
  270. }
  271. </style>