index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <!-- 货源 -->
  2. <template>
  3. <view class="content">
  4. <view class="banner">
  5. <image class="banner-img" src="@/static/images/goodSource/banner@2x.png" mode='widthFix'></image>
  6. <view class="head flex s-row paddingr35">
  7. <view class="flex flex-space-between">
  8. <view class="flex s-row item1" @click="goCity(0)">
  9. <view class="fontsize-28 gray">装车</view>
  10. <view class="fontsize-46 fontweight-500 text">{{startPlace.selected}}</view>
  11. </view>
  12. <image class="change-btn item2" src="@/static/images/goodSource/change.png" mode='widthFix'
  13. @click="changeCity"></image>
  14. <view class="flex s-row item3" @click="goCity(1)">
  15. <view class="fontsize-28 gray text-align-right">卸车</view>
  16. <view class="fontsize-46 fontweight-500 text">{{endPlace.selected}}</view>
  17. </view>
  18. </view>
  19. <view>
  20. <u-button type="" class="btn-color fontsize-36 m-top20" @click="upCallback({size:10,num:1})"> 查询
  21. </u-button>
  22. </view>
  23. </view>
  24. </view>
  25. <view :class="scrollTop>1200?'fixed1':''"></view>
  26. <view class="tab-view">
  27. <u-tabs :list="tabList" @click="clickTab" :lineColor="scrollTop>1200?'white':'#303133'" :current='tabIndex'
  28. :inactiveStyle="{color: scrollTop>1200?'white':'',}" :activeStyle="{
  29. color: scrollTop>1200?'white':'',
  30. fontWeight: 'bold',
  31. transform: 'scale(1.05)'
  32. }" :class="scrollTop>1200?'fixed':''"></u-tabs>
  33. <view class="tab-right" @click="selectType">
  34. <view>{{pickerSelect}}</view>
  35. <u-icon name="arrow-down" size="20"></u-icon>
  36. </view>
  37. </view>
  38. <u-picker :show="show" :columns="columns" :closeOnClickOverlay='true' @close='selectTypeClose'
  39. @cancel='selectTypeClose' @confirm='confirmSelectType'></u-picker>
  40. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
  41. <view :id="'good'+good.id" class="good-list" v-for="good in goods" :key="good.id"
  42. @click="toDetail(good.id)">
  43. <view style="padding: 0 35rpx 20rpx 35rpx;">
  44. <view class="flex flex-space-between">
  45. <view class="item1">
  46. <view class="ssx">辽</view>
  47. <view class="level2-title">{{good.sendCity}} {{good.sendArea}}</view>
  48. </view>
  49. <image class="jt-icon item2" src="@/static/images/goodSource/jt.png" mode='widthFix'></image>
  50. <view class="item3">
  51. <view class="ssx">京</view>
  52. <view class="level2-title">{{good.unloadCity}} {{good.unloadArea}}</view>
  53. </view>
  54. </view>
  55. <view class="right gray">
  56. 01.10
  57. </view>
  58. <view class="flex flex-space-between">
  59. <view class="left">
  60. <view class="flex">
  61. <view class="fontsize-25 gray mr20">货距 {{good.cargoDistance}}km</view>
  62. <view class="fontsize-25 gray ">运距 {{good.distance}}km</view>
  63. </view>
  64. <view class="flex fontsize-25 gray row">
  65. <view>{{good.goodsName}} | </view>
  66. <view>{{carLength(good)}} | {{carType(good)}} | {{carWeight(good)}}</view>
  67. </view>
  68. <view class="flex row">
  69. <view class="row-tips">{{good.taskDescription}}</view>
  70. </view>
  71. </view>
  72. <view class="right flex h-color">
  73. <view class="fontsize-46">
  74. {{good.freightPrice}}
  75. </view>
  76. <view class="flex dw">元/吨</view>
  77. </view>
  78. </view>
  79. </view>
  80. <view class="flex flex-space-between item-bottom">
  81. <view class="left flex row">
  82. <u--image :showLoading="true" :src="good.cargoOwnerPortrait" width="70rpx" height="70rpx"
  83. shape="circle">
  84. </u--image>
  85. <view class="name">{{good.cargoOwnerName}}</view>
  86. <!-- <view class="hp flex fontsize-24">
  87. <view class="gray">评分</view>
  88. <view class="number-color">99%</view>
  89. </view>
  90. <view class="sum flex fontsize-24">
  91. <view class="gray">发运次数</view>
  92. <view class="number-color">106</view>
  93. </view> -->
  94. </view>
  95. <view class="right">
  96. <view @click.stop="grabOrders(good)" class="qd">抢单</view>
  97. </view>
  98. </view>
  99. </view>
  100. </mescroll-body>
  101. <u-toast ref="uToast"></u-toast>
  102. </view>
  103. </template>
  104. <script>
  105. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  106. import {
  107. mapState
  108. } from 'vuex';
  109. import {
  110. apiGoods
  111. } from "@/api/mock.js"
  112. export default {
  113. mixins: [MescrollMixin], // 使用mixin
  114. data() {
  115. return {
  116. show: false,
  117. columns: [
  118. ['全部类型', '运费先付']
  119. ],
  120. startPlace: '1',
  121. endPlace: '2',
  122. goods: [], // 数据列表
  123. src: 'https://cdn.uviewui.com/uview/album/1.jpg',
  124. height: "", // 需要固定swiper的高度
  125. tabList: [
  126. // {
  127. // name: '全部'
  128. // },
  129. {
  130. name: '推荐'
  131. }, {
  132. name: '按时间'
  133. }, {
  134. name: '按距离'
  135. },
  136. // {
  137. // name: '运费先付'
  138. // },
  139. ],
  140. pickerSelect: '全部类型',
  141. tabIndex: 0,
  142. scrollTop: 0,
  143. count: 0
  144. }
  145. },
  146. onTabItemTap(e) {
  147. // tab 点击时执行,此处直接接收单击事件
  148. uni.pageScrollTo({
  149. scrollTop: 0,
  150. duration: 300
  151. });
  152. console.log(e)
  153. },
  154. created() {
  155. },
  156. computed: {
  157. ...mapState(['hasLogin', 'userInfo', 'firstAuthentication'])
  158. },
  159. onShow() {
  160. //获取上一次点击起装卸地
  161. console.log(uni.getStorageSync('fPlaceObj'))
  162. if (uni.getStorageSync('fPlaceObj')) {
  163. this.startPlace = uni.getStorageSync('fPlaceObj');
  164. } else {
  165. console.log(123)
  166. // this.getLngLat();
  167. }
  168. console.log(uni.getStorageSync('sPlaceObj'))
  169. if (uni.getStorageSync('sPlaceObj')) {
  170. this.endPlace = uni.getStorageSync('sPlaceObj');
  171. }
  172. },
  173. onLoad() {
  174. //#ifdef APP-PLUS
  175. // this.getLngLat();
  176. //#endif
  177. // let _isHave = this.$utils.getRoles('aaa')
  178. // console.log(_isHave)
  179. // var Ip=returnCitySN['cip']
  180. // var cityname=returnCitySN['cname']
  181. // localStorage.setItem('Ip', Ip)
  182. // console.log(localStorage.getItem('Ip', Ip))
  183. // localStorage.setItem('cityname', cityname)
  184. // console.log(localStorage.getItem('cityname', cityname))
  185. },
  186. onPageScroll(res) {
  187. this.scrollTop = res.scrollTop
  188. // console.log("页面滚动了", res.scrollTop)
  189. if (this.scrollTop > 1200) {
  190. uni.setTabBarItem({
  191. index: 0,
  192. text: '返回顶部',
  193. iconPath: 'static/images/common/top@2x.png',
  194. selectedIconPath: 'static/images/common/top@2x.png'
  195. })
  196. } else {
  197. uni.setTabBarItem({
  198. index: 0,
  199. text: '货源',
  200. iconPath: 'static/images/common/huoyuan@2x(1).png',
  201. selectedIconPath: 'static/images/common/huoyuan@2x.png'
  202. })
  203. }
  204. },
  205. methods: {
  206. carLength(good) {
  207. let length = ''
  208. if (good.carLengthSmall && good.carLength) {
  209. length = good.carLengthSmall + '~' + good.carLength + '米'
  210. } else if (good.carLengthSmall) {
  211. length = "大于" + good.carLengthSmall + '米'
  212. } else if (good.carLength) {
  213. length = "小于" + good.carLength + '米'
  214. }
  215. return length
  216. },
  217. carType(good) {
  218. let _val = '';
  219. if (good.carModel == 1) {
  220. _val = '不限'
  221. } else {
  222. if (good.carModel.includes(2)) {
  223. _val += '高栏/'
  224. }
  225. if (good.carModel.includes(3)) {
  226. _val += '集装箱/'
  227. }
  228. if (good.carModel.includes(4)) {
  229. _val += '自卸车'
  230. }
  231. }
  232. return _val
  233. },
  234. carWeight(good) {
  235. good.loadWeightSmall
  236. good.loadWeight
  237. let weight = ''
  238. if (good.loadWeightSmall && good.loadWeight) {
  239. weight = good.loadWeightSmall + '~' + good.loadWeight + '吨'
  240. } else if (good.loadWeightSmall) {
  241. weight = "大于" + good.loadWeightSmall + '吨'
  242. } else if (good.loadWeight) {
  243. weight = "小于" + good.loadWeight + '吨'
  244. }
  245. return weight
  246. },
  247. getdate() {
  248. var date = new Date()
  249. var year = date.getFullYear() //获取完整的年份(4位)
  250. var mouth = date.getMonth() + 1 //获取当前月份(0-11,0代表1月)
  251. var datetime = date.getDate() //获取当前日(1-31)
  252. if (mouth < 10) {
  253. mouth = '0' + mouth
  254. }
  255. if (datetime < 10) {
  256. datetime = '0' + datetime
  257. }
  258. return String(year) + String(mouth) + String(datetime)
  259. },
  260. grabOrders(item) {
  261. let _obj = {
  262. driverCommonId: this.firstAuthentication.commonId,
  263. commonId: item.commonId,
  264. cargoOwnerName: item.cargoOwnerName,
  265. cargoOwner: item.cargoOwner,
  266. sendPrivate: item.sendPrivate,
  267. sendCity: item.sendCity,
  268. sendArea: item.sendArea,
  269. sendDetailedAddress: item.sendDetailedAddress,
  270. unloadPrivate: item.unloadPrivate,
  271. unloadCity: item.unloadCity,
  272. unloadArea: item.unloadArea,
  273. unloadDetailedAddress: item.unloadDetailedAddress,
  274. goodsName: item.goodsName,
  275. distance: item.distance,
  276. freightPrice: item.freightPrice,
  277. driverName: this.firstAuthentication.driverName,
  278. driverPhone: this.firstAuthentication.driverPhone,
  279. cargoOwnerPhone: item.cargoOwnerPhone
  280. }
  281. this.$request.baseRequest('post', '/publishTaskInfo/api/addOrder', _obj).then(res => {
  282. debugger
  283. if (res.code == 200) {
  284. this.$refs.uToast.show({
  285. type: 'success',
  286. message: "抢单成功!",
  287. complete() {
  288. uni.switchTab({
  289. url: "/pages/order/index"
  290. })
  291. }
  292. })
  293. }
  294. })
  295. .catch(res => {
  296. uni.$u.toast(res.message);
  297. });
  298. },
  299. confirmSelectType(val) {
  300. debugger
  301. console.log(val)
  302. this.pickerSelect = val.value[0]
  303. this.show = false
  304. },
  305. selectTypeClose() {
  306. this.show = false
  307. },
  308. selectType() {
  309. this.show = true
  310. },
  311. getLngLat() {
  312. console.log(11111111111111111111111111111111111111111111111111111)
  313. uni.getLocation({
  314. type: 'gcj02',
  315. geocode: true,
  316. success: res => {
  317. console.log('--------------------------------')
  318. console.log(res)
  319. if (res.latitude) {
  320. this.lat = res.latitude + ',' + res.longitude;
  321. this.startPlace = res.address.city
  322. // this.lng = res.longitude;
  323. } else {
  324. console.log(uni.getSystemInfoSync().platform)
  325. if (uni.getSystemInfoSync().platform == 'android') {
  326. var context = plus.android.importClass("android.content.Context");
  327. var locationManager = plus.android.importClass(
  328. "android.location.LocationManager");
  329. var main = plus.android.runtimeMainActivity();
  330. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  331. this.bool = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)
  332. }
  333. if (this.bool === false) {
  334. uni.showModal({
  335. title: '提示',
  336. content: '请打开定位服务',
  337. success: ({
  338. confirm,
  339. cancel
  340. }) => {
  341. if (confirm) {
  342. if (uni.getSystemInfoSync().platform == 'android') {
  343. var Intent = plus.android.importClass(
  344. 'android.content.Intent');
  345. var Settings = plus.android.importClass(
  346. 'android.provider.Settings');
  347. var intent = new Intent(Settings
  348. .ACTION_LOCATION_SOURCE_SETTINGS);
  349. var main = plus.android.runtimeMainActivity();
  350. main.startActivity(intent); // 打开系统设置GPS服务页面
  351. }
  352. }
  353. }
  354. });
  355. }
  356. }
  357. }
  358. });
  359. },
  360. toDetail(id) {
  361. uni.$u.route('/pages/goodSource/shippingDetails', {
  362. id: id,
  363. });
  364. },
  365. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  366. upCallback(page) {
  367. let _pickerSelect;
  368. if (this.pickerSelect == '运费先付') {
  369. _pickerSelect = 1
  370. } else {
  371. _pickerSelect = 0
  372. }
  373. this.$request.baseRequest('get', '/publishTaskInfo/selectGoodsSource', {
  374. // searchKeyWord: this.tabIndex + 1,
  375. // searchType: _pickerSelect,
  376. loadingPlace: this.startPlace.selected,
  377. unLoadingPlace: this.endPlace.selected,
  378. pageSize: page.size,
  379. currentPage: page.num,
  380. // loadingPlaceCity: this.startPlace.fchoosecity,
  381. // unLoadingPlaceCity: this.endPlace.schoosecity
  382. }).then(res => {
  383. if (res.code == 200) {
  384. this.goods = res.data.records
  385. this.mescroll.endBySize(res.data.records.length, res.data.total);
  386. }
  387. })
  388. .catch(res => {
  389. uni.$u.toast(res.message);
  390. this.mescroll.endErr();
  391. });
  392. // 此处可以继续请求其他接口
  393. // if(page.num == 1){
  394. // // 请求其他接口...
  395. // }
  396. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  397. // if(!this.isInitxx){
  398. // apiGetxx().then(res=>{
  399. // this.isInitxx = true
  400. // this.mescroll.resetUpScroll() // 重新触发upCallback
  401. // }).catch(()=>{
  402. // this.mescroll.endErr()
  403. // })
  404. // return // 此处return,先获取xx
  405. // }
  406. // //联网加载数据
  407. // apiGoods(page.num, page.size).then(res => {
  408. // //联网成功的回调,隐藏下拉刷新和上拉加载的状态;
  409. // //mescroll会根据传的参数,自动判断列表如果无任何数据,则提示空;列表无下一页数据,则提示无更多数据;
  410. // //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  411. // //this.mescroll.endByPage(res.list.length, totalPage); //必传参数(当前页的数据个数, 总页数)
  412. // //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  413. // this.mescroll.endBySize(res.list.length, totalSize); //必传参数(当前页的数据个数, 总数据量)
  414. // //方法三(推荐): 您有其他方式知道是否有下一页 hasNext
  415. // //this.mescroll.endSuccess(res.list.length, hasNext); //必传参数(当前页的数据个数, 是否有下一页true/false)
  416. // //方法四 (不推荐),会存在一个小问题:比如列表共有20条数据,每页加载10条,共2页.如果只根据当前页的数据个数判断,则需翻到第三页才会知道无更多数据
  417. // // this.mescroll.endSuccess(res.list.length);
  418. // //设置列表数据
  419. // if (page.num == 1) this.goods = []; //如果是第一页需手动制空列表
  420. // this.goods = this.goods.concat(res.list); //追加新数据
  421. // }).catch(() => {
  422. // //联网失败, 结束加载
  423. // this.mescroll.endErr();
  424. // })
  425. },
  426. clickTab(val) {
  427. console.log(val)
  428. },
  429. changeCity() {
  430. if (this.endPlace == '全国') {
  431. this.$refs.uToast.show({
  432. type: 'error',
  433. message: "卸车地为全国不允许切换!",
  434. })
  435. return
  436. }
  437. [this.startPlace, this.endPlace] = [this.endPlace, this.startPlace];
  438. },
  439. goCity(type) {
  440. uni.$u.route('/pages/goodSource/selectCity', {
  441. startPlace: this.startPlace,
  442. endPlace: this.endPlace,
  443. type: type
  444. });
  445. console.log(type)
  446. },
  447. swiperChange(e) {
  448. this.tabIndex = e.detail.current
  449. }
  450. }
  451. }
  452. </script>
  453. <style scoped lang="scss">
  454. .banner {
  455. width: 100%;
  456. position: relative;
  457. }
  458. .fixed,
  459. .fixed1 {
  460. background: linear-gradient(97deg, #4FABFD 0%, #2772FB 100%);
  461. position: fixed;
  462. top: var(--status-bar-height);
  463. z-index: 999;
  464. // width: calc(100% - 40rpx);
  465. width: 100%;
  466. // margin:0 20rpx;
  467. }
  468. .fixed1 {
  469. top: 0;
  470. height: var(--status-bar-height);
  471. background: linear-gradient(97deg, #4FABFD 0%, #2772FB 100%);
  472. }
  473. .banner-img {
  474. width: 100%;
  475. }
  476. .head {
  477. position: absolute;
  478. width: calc(100% - 108rpx);
  479. bottom: 0;
  480. background: white;
  481. margin: 0 20rpx;
  482. border-radius: 20rpx;
  483. .item1,
  484. .item3 {
  485. width: 40%;
  486. .text {
  487. text-overflow: ellipsis;
  488. overflow: hidden;
  489. white-space: nowrap;
  490. }
  491. }
  492. .item1 .text {
  493. text-align: left;
  494. }
  495. .item3 .text {
  496. text-align: right;
  497. }
  498. }
  499. .change-btn {
  500. width: 86rpx;
  501. height: 86rpx;
  502. }
  503. .good-list {
  504. background-color: white;
  505. margin: 20rpx;
  506. padding: 20rpx 0rpx 0 0;
  507. border-radius: 20rpx;
  508. .item1,
  509. .item3 {
  510. width: 40%;
  511. display: flex;
  512. .text {
  513. text-overflow: ellipsis;
  514. overflow: hidden;
  515. white-space: nowrap;
  516. }
  517. }
  518. .item1 .text {
  519. text-align: left;
  520. }
  521. .item3 .text {
  522. text-align: right;
  523. }
  524. }
  525. .jt-icon {
  526. position: relative;
  527. top: 6rpx;
  528. width: 60rpx;
  529. margin: 0 20rpx;
  530. }
  531. .row {
  532. margin: 10rpx 0;
  533. align-items: center;
  534. }
  535. .item-bottom {
  536. background: #F0F5FF;
  537. padding: 0 30rpx;
  538. .name {
  539. font-size: 26rpx;
  540. font-weight: 700;
  541. color: #000000;
  542. margin-left: 30rpx;
  543. }
  544. .hp {
  545. margin: 30rpx;
  546. }
  547. .number-color {
  548. margin: 0 10rpx;
  549. }
  550. .qd {
  551. background: linear-gradient(97deg, #4FABFD 0%, #2772FB 100%);
  552. border-radius: 13px;
  553. font-size: 29rpx;
  554. font-weight: 400;
  555. color: #FFFFFF;
  556. padding: 10rpx 35rpx;
  557. }
  558. }
  559. .dw {
  560. align-items: center;
  561. }
  562. .place {
  563. height: var(--status-bar-height);
  564. }
  565. .tab-view {
  566. display: flex;
  567. align-items: center;
  568. justify-content: space-between;
  569. }
  570. .tab-right {
  571. display: flex;
  572. margin-right: 20rpx;
  573. align-items: center;
  574. }
  575. </style>