index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view class="bg min100 pb-20">
  3. <u-sticky h5-nav-height="0">
  4. <view class="status_bar bg-blue">
  5. </view>
  6. <view class="bg-blue white">
  7. <view class="center pd-20" @click="getCity" style="padding-top: 52rpx;">
  8. <view class="size-36 mr-10">{{city}}</view>
  9. <u-icon name="arrow-down"></u-icon>
  10. </view>
  11. <u-tabs v-if="tabList.length>1" :list="tabList" font-size="32" bg-color="#286ceb" height="90" active-color="#fff"
  12. inactive-color="#eee" :is-scroll="false" :current="index" @change="change"></u-tabs>
  13. </view>
  14. </u-sticky>
  15. <view class="pd-30">
  16. <empty v-if="list.length==0" text="暂无订单"></empty>
  17. <view v-for="(item,i) in list" :key="i" class="mb-30">
  18. <orderItem v-if="current==0" :type="1" :item="item"></orderItem>
  19. <sfItem v-if="current==1" type="1" :item="item"></sfItem>
  20. <hyItem v-if="current==2" type="1" :item="item"></hyItem>
  21. </view>
  22. <u-loadmore v-show="list.length>9" :status="status" icon-type="flower" bg-color="transperant" margin-top="30"
  23. margin-bottom="30" />
  24. <image @click="toPublish" type="1" v-if="current==1" src="../../static/sf-pub.png" style="width: 100rpx;height: 100rpx;position: fixed;bottom: 120rpx;right: 20rpx;"
  25. mode=""></image>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. mapState
  32. } from 'vuex'
  33. export default {
  34. computed: {
  35. ...mapState(['city', 'tabList'])
  36. },
  37. data() {
  38. return {
  39. index: 0,
  40. current: '',
  41. page: 1,
  42. status: 'loadmore',
  43. list: [],
  44. timer1: null,
  45. timer2: null,
  46. timer3: null,
  47. flag: false
  48. }
  49. },
  50. onShow() {
  51. this.flag = false;
  52. this.page = 1
  53. this.list = []
  54. this.status = 'loadmore'
  55. this.timer3 = setInterval(() => {
  56. if (this.tabList && this.tabList[0]) {
  57. clearInterval(this.timer3)
  58. this.timer3 = null
  59. if (!this.current) {
  60. this.current = this.tabList[0].id
  61. }
  62. // 列表接口
  63. if (this.city) {
  64. console.log(666);
  65. if (this.current == 0) {
  66. this.getList1()
  67. }else if (this.current == 1) {
  68. this.getList2()
  69. }else if (this.current == 2) {
  70. this.getList3()
  71. }
  72. } else {
  73. let _this = this
  74. uni.getLocation({
  75. type: 'gcj02',
  76. geocode: true,
  77. success(res) {
  78. let city = res.address ? res.address.city : '普洱市'
  79. _this.$store.commit('getCity', city)
  80. if (_this.current == 0) {
  81. _this.getList1()
  82. } else if (_this.current == 1) {
  83. _this.getList2()
  84. }else if (_this.current == 2) {
  85. _this.getList3()
  86. }
  87. },
  88. fail() {
  89. if (_this.current == 0) {
  90. _this.getList1()
  91. } else if (_this.current == 1) {
  92. _this.getList2()
  93. }else if (_this.current == 2) {
  94. _this.getList3()
  95. }
  96. }
  97. });
  98. }
  99. // 实时更新新下的单
  100. if (!this.timer1) {
  101. this.timer1 = setInterval(() => {
  102. if (this.current == 0 && this.flag) {
  103. this.$http('/addons/ddrive/order/order_refresh', {
  104. order_id: this.list.length > 0 ? this.list[0].id : '',
  105. city: this.city || ''
  106. }, "POST").then(data => {
  107. if (data.length > 0) {
  108. data.forEach(item => {
  109. this.list.unshift(item)
  110. })
  111. }
  112. })
  113. } else if (this.current == 1 && this.flag) {
  114. this.$http('/addons/ddrive/sforder/order_refresh', {
  115. order_type: 1,
  116. order_id: this.list.length > 0 ? this.list[0].id : '',
  117. city: this.city || ''
  118. }, "POST").then(data => {
  119. if (data.length > 0) {
  120. data.forEach(item => {
  121. this.list.unshift(item)
  122. })
  123. }
  124. })
  125. }else if (this.current == 2 && this.flag) {
  126. this.$http('/addons/ddrive/hyorder/order_refresh', {
  127. order_id: this.list.length > 0 ? this.list[0].id : '',
  128. city: this.city || ''
  129. }, "POST").then(data => {
  130. if (data.length > 0) {
  131. data.forEach(item => {
  132. this.list.unshift(item)
  133. })
  134. }
  135. })
  136. }
  137. }, 1000)
  138. }
  139. // 实时更新减少的单
  140. if (!this.timer2) {
  141. this.timer2 = setInterval(() => {
  142. if (this.list.length > 0 && this.current == 0) {
  143. this.$http('/addons/ddrive/order/order_eliminate', {
  144. city: this.city || ''
  145. }, "POST").then(data => {
  146. if (data.length > 0) {
  147. this.list.forEach((item, i) => {
  148. if (data.includes(item.id * 1)) {
  149. this.list.splice(i, 1)
  150. }
  151. })
  152. }
  153. })
  154. }else if (this.list.length > 0 && this.current == 1) {
  155. this.$http('/addons/ddrive/sforder/order_eliminate', {
  156. order_type: 1,
  157. city: this.city || ''
  158. }, "POST").then(data => {
  159. if (data.length > 0) {
  160. this.list.forEach((item, i) => {
  161. if (data.includes(item.id * 1)) {
  162. this.list.splice(i, 1)
  163. }
  164. })
  165. }
  166. })
  167. }else if (this.list.length > 0 && this.current == 2) {
  168. this.$http('/addons/ddrive/hyorder/order_eliminate', {
  169. city: this.city || ''
  170. }, "POST").then(data => {
  171. if (data.length > 0) {
  172. this.list.forEach((item, i) => {
  173. if (data.includes(item.id * 1)) {
  174. this.list.splice(i, 1)
  175. }
  176. })
  177. }
  178. })
  179. }
  180. }, 5000)
  181. }
  182. }
  183. }, 200)
  184. },
  185. onUnload() {
  186. clearInterval(this.timer1)
  187. clearInterval(this.timer2)
  188. clearInterval(this.timer3)
  189. this.timer1 = null
  190. this.timer2 = null
  191. this.timer3 = null
  192. },
  193. onHide() {
  194. clearInterval(this.timer1)
  195. clearInterval(this.timer2)
  196. clearInterval(this.timer3)
  197. this.timer1 = null
  198. this.timer2 = null
  199. this.timer3 = null
  200. },
  201. onPullDownRefresh() {
  202. this.page = 1
  203. this.flag = false
  204. this.list = []
  205. if (this.current == 0) {
  206. this.getList1()
  207. } else if (this.current == 1) {
  208. this.getList2()
  209. }else if (this.current == 2) {
  210. this.getList3()
  211. }
  212. },
  213. onReachBottom() {
  214. //避免多次触发
  215. if (this.status == 'loading' || this.status == 'nomore') {
  216. return;
  217. }
  218. if (this.current == 0) {
  219. this.getList1()
  220. } else if (this.current == 1) {
  221. this.getList2()
  222. }else if (this.current == 2) {
  223. this.getList3()
  224. }
  225. },
  226. components: {},
  227. methods: {
  228. //代驾
  229. getList1() {
  230. this.flag = false
  231. this.status = "loading";
  232. this.$http('/addons/ddrive/order/takingList', {
  233. page: this.page,
  234. city: this.city
  235. }, "POST").then(res => {
  236. let data = res.data
  237. if (data.length < 10) {
  238. this.status = "nomore"
  239. } else {
  240. this.page = this.page + 1
  241. this.status = "loadmore"
  242. }
  243. this.list = this.list.concat(data)
  244. this.flag = true
  245. uni.stopPullDownRefresh();
  246. })
  247. },
  248. //顺风车
  249. getList2() {
  250. this.flag = false
  251. this.status = "loading";
  252. this.$http('/addons/ddrive/sforder/order_index', {
  253. page: this.page,
  254. start_city: this.city,
  255. order_type: 1
  256. }, "POST").then(res => {
  257. let data = res
  258. if (data.length < 10) {
  259. this.status = "nomore"
  260. } else {
  261. this.page = this.page + 1
  262. this.status = "loadmore"
  263. }
  264. this.list = this.list.concat(data)
  265. this.flag = true
  266. uni.stopPullDownRefresh();
  267. })
  268. },
  269. //货运
  270. getList3(){
  271. this.flag = false
  272. this.status = "loading";
  273. this.$http('/addons/ddrive/hyorder/taskingList', {
  274. page: this.page,
  275. city: this.city,
  276. }, "POST").then(res => {
  277. let data = res.data
  278. if (data.length < 10) {
  279. this.status = "nomore"
  280. } else {
  281. this.page = this.page + 1
  282. this.status = "loadmore"
  283. }
  284. this.list = this.list.concat(data)
  285. this.flag = true
  286. uni.stopPullDownRefresh();
  287. })
  288. },
  289. change(index) {
  290. this.index = index;
  291. this.current = this.tabList[index].id;
  292. this.page = 1;
  293. this.flag = false;
  294. this.list = [];
  295. if (this.current == 0) {
  296. this.getList1()
  297. } else if (this.current == 1) {
  298. this.getList2()
  299. }else if (this.current == 2) {
  300. this.getList3()
  301. }
  302. },
  303. getCity() {
  304. uni.navigateTo({
  305. url: '/pages/home/city'
  306. })
  307. },
  308. // 顺风车发布
  309. toPublish() {
  310. uni.navigateTo({
  311. url: '/pages/shunfeng/publish'
  312. })
  313. }
  314. }
  315. }
  316. </script>
  317. <style scoped lang="scss">
  318. </style>