index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <!-- index.wxml -->
  3. <view class="wrap">
  4. <view class="cate_list">
  5. <van-tabs :active="type" line-width="59rpx" line-height="4rpx" title-active-color="#D54C43" title-inactive-color="#333333" @click="onChange">
  6. <!-- <van-tab title="当前订单" name="{{ 1 }}"></van-tab>
  7. <van-tab title="历史订单" name="{{ 2 }}"></van-tab> -->
  8. <van-tab title="全部" name="-1"></van-tab>
  9. <van-tab title="未支付" name="0"></van-tab>
  10. <van-tab title="待发货" name="1"></van-tab>
  11. <van-tab title="待自提" name="2"></van-tab>
  12. <van-tab title="已完成" name="3"></van-tab>
  13. </van-tabs>
  14. </view>
  15. <view class="order_list">
  16. <view class="order_item" @tap="goDetail" :data-id="item.id" v-for="(item, index) in dataList" :key="index">
  17. <view class="item_t">
  18. <view class="item_t_l">
  19. <view class="item_t_l_t">
  20. <view class="item_tag">{{ item.fare_type ? '自取' : '外卖' }}</view>
  21. <view class="shop_name">{{ item.store.title }}</view>
  22. </view>
  23. <view class="order_time">下单时间:{{ item.created_at }}</view>
  24. </view>
  25. <view class="item_t_r">
  26. <text class="" v-if="item.fare_type == 1">
  27. {{ item.order_status == 2 ? '已完成' : item.order_status == 0 ? '已关闭' : item.pay_status != 1 ? '待支付' : item.ship_status ? '已自提' : '待自提' }}
  28. </text>
  29. <text class="send_time" v-if="item.fare_type == 0 && item.order_status == 1 && item.ship_status == 1">{{ item.count_time }}</text>
  30. <text class="" v-if="item.fare_type == 0">
  31. {{ item.order_status == 2 ? '已完成' : item.order_status == 0 ? '已关闭' : item.pay_status != 1 ? '待支付' : item.ship_status ? '配送中' : '待配送' }}
  32. </text>
  33. <van-icon name="arrow" />
  34. </view>
  35. </view>
  36. <view class="item_nr">
  37. <view class="item_goods">
  38. <image class="goods_tu" :src="imgUrl + img" v-for="(img, index1) in item.thumbArrCustom" :key="index1"></image>
  39. <image class="goods_tu_more" v-if="item.thumbArrLength > 3" src="/static/statics/img/more_tu.png"></image>
  40. </view>
  41. <view class="item_total">
  42. <view class="price">
  43. <text class="unit">¥</text>
  44. {{ item.pay_price }}
  45. </view>
  46. <view class="num">共{{ item.goodsNums }}件</view>
  47. </view>
  48. </view>
  49. <view class="item_btns">
  50. <view class="btn cancel" v-if="item.ship_status == 0 && item.order_status == 1" :data-id="item.id" :data-item="item" @tap.stop.prevent="cancleOrder">
  51. 取消订单
  52. </view>
  53. <view class="btn" v-if="item.order_status == 1 && item.pay_status != 1" :data-id="item.id" @tap.stop.prevent="goTopay">立即支付</view>
  54. <view class="btn" v-if="item.pay_status == 1 && item.ship_status == 1 && item.order_status == 1" :data-id="item.id" @tap.stop.prevent="receiveOrder">收货</view>
  55. <view class="btn" v-if="item.order_status == 2" @tap.stop.prevent="toGoods">再来一单</view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- loading -->
  61. <!-- <van-overlay show="{{ loading }}" z-index="100">
  62. <van-loading custom-class="custom_loading" />
  63. </van-overlay> -->
  64. </template>
  65. <script>
  66. // index.js
  67. let myPro = require('../../../../utils/wxRequest.js');
  68. let util = require('../../../../utils/util.js');
  69. export default {
  70. data() {
  71. return {
  72. imgUrl: getApp().globalData.imgUrl,
  73. type: '-1',
  74. // 订单状态 空全部(-1) 0未支付 1待发货 2待自提 3已完成
  75. page: 1,
  76. size: 10,
  77. dataList: [],
  78. finished: false,
  79. loading: false,
  80. // 配送计时器
  81. timer: null,
  82. img: ''
  83. };
  84. },
  85. onLoad: function (options) {
  86. // Do some initialize when page load.
  87. let that = this;
  88. if (options.type) {
  89. that.setData({
  90. type: options.type
  91. });
  92. console.log('type', that.type, typeof that.type);
  93. }
  94. },
  95. onShow: function () {
  96. // Do something when page show.
  97. let that = this; // 验证登录
  98. getApp().globalData.verifyLogin(function (loginStatus) {
  99. // console.log('登录状态',loginStatus)
  100. if (loginStatus) {
  101. that.setData({
  102. page: 1,
  103. dataList: [],
  104. finished: false
  105. });
  106. that.getDataList();
  107. }
  108. });
  109. },
  110. onReady: function () {
  111. // Do something when page ready.
  112. },
  113. onHide: function () {
  114. // Do something when page hide.
  115. },
  116. onUnload: function () {
  117. // Do something when page close.
  118. },
  119. onPullDownRefresh: function () {
  120. // Do something when pull down.
  121. let that = this;
  122. that.setData({
  123. page: 1,
  124. dataList: [],
  125. finished: false
  126. });
  127. that.getDataList(); //停止当前页面下拉刷新
  128. uni.stopPullDownRefresh();
  129. },
  130. onReachBottom: function () {
  131. // Do something when page reach bottom.
  132. let that = this;
  133. if (!that.finished) {
  134. that.getDataList();
  135. }
  136. },
  137. onPageScroll: function () {
  138. // Do something when page scroll
  139. },
  140. onResize: function () {
  141. // Do something when page resize
  142. },
  143. methods: {
  144. // 订单列表
  145. getDataList() {
  146. let that = this;
  147. clearInterval(that.timer);
  148. let params = {
  149. page: that.page,
  150. size: that.size
  151. };
  152. if (that.type != -1) {
  153. params.status = that.type;
  154. }
  155. myPro
  156. .wxRequest('user/order/list', 'GET', params)
  157. .then((res) => {
  158. let list = res.result; // 无数据
  159. if (list.length == 0) {
  160. uni.showToast({
  161. title: '暂无更多数据',
  162. icon: 'none'
  163. });
  164. that.setData({
  165. finished: true
  166. });
  167. } else {
  168. for (let i in list) {
  169. list[i].goodsNums = 0; // 单笔订单的商品总数
  170. list[i].thumbArr = []; // 单笔订单的商品图片
  171. for (let j in list[i].order_good) {
  172. let goods = list[i].order_good[j];
  173. list[i].goodsNums += parseInt(goods.nums);
  174. list[i].thumbArr.push(goods.good_thumb);
  175. }
  176. list[i].thumbArrLength = list[i].thumbArr.length; // 单笔订单的商品图片数量
  177. // 多于三张截取
  178. if (list[i].thumbArr.length > 3) {
  179. list[i].thumbArrCustom = list[i].thumbArr.slice(0, 3);
  180. } else {
  181. list[i].thumbArrCustom = list[i].thumbArr;
  182. }
  183. }
  184. if (that.page == 1) {
  185. that.setData({
  186. dataList: list
  187. });
  188. } else {
  189. that.setData({
  190. dataList: that.dataList.concat(list)
  191. });
  192. }
  193. that.setData({
  194. page: that.page + 1
  195. }); // 开启定时
  196. if (that.type == 1) {
  197. that.newTimer();
  198. }
  199. }
  200. })
  201. .catch((err) => {
  202. console.log('报错信息', err);
  203. uni.showToast({
  204. title: err,
  205. icon: 'none'
  206. });
  207. });
  208. },
  209. // 切换tab
  210. onChange(event) {
  211. console.log(event.detail.name, typeof event.detail.name);
  212. let that = this;
  213. that.setData({
  214. type: event.detail.name,
  215. page: 1,
  216. dataList: [],
  217. finished: false
  218. });
  219. that.getDataList();
  220. },
  221. // 去详情
  222. goDetail(event) {
  223. let that = this;
  224. let id = event.currentTarget.dataset.id;
  225. uni.navigateTo({
  226. url: '/pages/user/order/detail/index?order_id=' + id
  227. });
  228. },
  229. // 取消订单
  230. cancleOrder(event) {
  231. let that = this;
  232. let item = event.currentTarget.dataset.item; // 未支付的订单可以取消
  233. if (item.order_status == 1 && item.pay_status != 1) {
  234. // 取消订单
  235. myPro
  236. .wxRequest('user/v2/order/cancelorder', 'POST', {
  237. order_id: item.id
  238. })
  239. .then((res) => {
  240. uni.showToast({
  241. title: res.msg,
  242. icon: 'none'
  243. });
  244. that.setData({
  245. page: 1,
  246. dataList: [],
  247. finished: false
  248. });
  249. that.getDataList();
  250. })
  251. .catch((err) => {
  252. console.log('报错信息', err);
  253. uni.showToast({
  254. title: err,
  255. icon: 'none'
  256. });
  257. });
  258. } else {
  259. // 已支付的订单要联系商家
  260. uni.showModal({
  261. title: '可联系商家取消',
  262. content: '商家电话' + item.store.phone,
  263. showCancel: false,
  264. confirmText: '我知道了',
  265. confirmColor: '#000000'
  266. });
  267. }
  268. },
  269. // 收货
  270. receiveOrder(event) {
  271. let that = this;
  272. let order_id = event.currentTarget.dataset.id;
  273. let params = {
  274. order_id: order_id
  275. };
  276. myPro
  277. .wxRequest('user/order/commit', 'POST', params)
  278. .then((res) => {
  279. uni.showToast({
  280. title: res.msg,
  281. icon: 'none'
  282. });
  283. that.setData({
  284. page: 1,
  285. dataList: [],
  286. finished: false
  287. });
  288. that.getDataList();
  289. })
  290. .catch((err) => {
  291. console.log('报错信息', err);
  292. uni.showToast({
  293. title: err,
  294. icon: 'none'
  295. });
  296. });
  297. },
  298. // 再来一单
  299. toGoods() {
  300. let that = this;
  301. uni.reLaunch({
  302. url: '/pages/goods/index'
  303. });
  304. },
  305. // 去支付
  306. goTopay(event) {
  307. let that = this;
  308. let id = event.currentTarget.dataset.id;
  309. uni.navigateTo({
  310. url: '/pages/pay-order/index?order_id=' + id
  311. });
  312. },
  313. // 配送计时
  314. newTimer() {
  315. let that = this;
  316. let list = that.dataList;
  317. clearInterval(that.timer);
  318. that.timer = setInterval(function () {
  319. for (let i in list) {
  320. // 当前订单为外卖单且正在配送,开启倒计时
  321. if (list[i].fare_type == 0 && list[i].order_status == 1 && list[i].ship_status) {
  322. let ship_at = list[i].ship_at;
  323. if (!list[i].isend) {
  324. let shijian = util.daojishi(ship_at, 30);
  325. list[i].count_time = shijian['timeStr'];
  326. list[i].isend = shijian['isend'];
  327. }
  328. }
  329. }
  330. that.setData({
  331. dataList: list
  332. });
  333. }, 1000);
  334. }
  335. }
  336. };
  337. </script>
  338. <style>
  339. /**index.wxss**/
  340. .wrap {
  341. min-height: 100vh;
  342. background: #f6f6f6;
  343. }
  344. .order_list {
  345. padding-top: 90rpx;
  346. }
  347. .order_item {
  348. margin-top: 20rpx;
  349. padding: 30rpx;
  350. background: #ffffff;
  351. }
  352. .order_item .item_t {
  353. display: flex;
  354. align-items: flex-start;
  355. justify-content: space-between;
  356. }
  357. .order_item .item_t_l_t {
  358. display: flex;
  359. align-items: center;
  360. }
  361. .order_item .item_tag {
  362. font-size: 22rpx;
  363. color: #ffffff;
  364. padding: 4rpx 10rpx;
  365. background: #295c57;
  366. border-radius: 5rpx;
  367. }
  368. .order_item .shop_name {
  369. font-size: 30rpx;
  370. color: #080808;
  371. font-weight: bold;
  372. padding-left: 8rpx;
  373. }
  374. .order_item .order_time {
  375. padding-top: 16rpx;
  376. color: rgba(8, 8, 8, 0.54);
  377. font-size: 26rpx;
  378. }
  379. .order_item .item_t_r {
  380. font-size: 28rpx;
  381. color: rgba(8, 8, 8, 0.54);
  382. display: flex;
  383. align-items: center;
  384. }
  385. .order_item .item_nr {
  386. display: flex;
  387. align-items: center;
  388. justify-content: space-between;
  389. margin-top: 34rpx;
  390. }
  391. .order_item .goods_tu {
  392. width: 138rpx;
  393. height: 138rpx;
  394. border-radius: 5rpx;
  395. margin-right: 20rpx;
  396. }
  397. .order_item .item_total .price {
  398. color: #080808;
  399. font-size: 34rpx;
  400. }
  401. .order_item .item_total .price .unit {
  402. font-size: 22rpx;
  403. }
  404. .order_item .item_total .num {
  405. padding-top: 10;
  406. font-size: 24rpx;
  407. color: rgba(8, 8, 8, 0.54);
  408. }
  409. .order_item .item_btns {
  410. display: flex;
  411. justify-content: flex-end;
  412. margin-top: 20rpx;
  413. }
  414. .order_item .item_btns .btn {
  415. width: 180rpx;
  416. height: 60rpx;
  417. background: rgba(41, 92, 86, 0.05);
  418. border: 1px solid #295c57;
  419. border-radius: 5rpx;
  420. font-size: 30rpx;
  421. color: #295c56;
  422. display: flex;
  423. align-items: center;
  424. justify-content: center;
  425. margin-left: 18rpx;
  426. }
  427. .order_item .item_btns .btn.cancel {
  428. border-color: #999999;
  429. color: #999999;
  430. background: transparent;
  431. }
  432. .order_item .send_time {
  433. padding-right: 16rpx;
  434. color: #ed8c17;
  435. }
  436. .order_item .item_goods {
  437. display: flex;
  438. align-items: center;
  439. }
  440. .order_item .goods_tu_more {
  441. width: 36rpx;
  442. height: 7rpx;
  443. }
  444. </style>