index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <view>
  3. <view class='my-order'>
  4. <!-- 顶部统计 -->
  5. <view class='header bg-color'>
  6. <view class='picTxt acea-row row-between-wrapper'>
  7. <view class='text'>
  8. <view class='name'>订单信息</view>
  9. </view>
  10. <view class='pictrue'>
  11. <image src='../../../static/images/orderTime.png'></image>
  12. </view>
  13. </view>
  14. </view>
  15. <view class='nav acea-row row-around'>
  16. <view class='item' :class='orderStatus === undefined ? "on": ""' @click="statusClick()">
  17. <view>全部</view>
  18. <view class='num'>{{ orderData.allCount || 0}}</view>
  19. </view>
  20. <view class='item' :class='orderStatus === 0 ? "on": ""' @click="statusClick(0)">
  21. <view>待付款</view>
  22. <view class='num'>{{orderData.unpaidCount || 0}}</view>
  23. </view>
  24. <view class='item' :class='orderStatus === 10 ? "on": ""' @click="statusClick(10)">
  25. <view>待发货</view>
  26. <view class='num'>{{orderData.undeliveredCount || 0}}</view>
  27. </view>
  28. <view class='item' :class='orderStatus === 20 ? "on": ""' @click="statusClick(20)">
  29. <view>待收货</view>
  30. <view class='num '>{{orderData.deliveredCount || 0}}</view>
  31. </view>
  32. <view class='item' :class='orderStatus === 30 ? "on": ""' @click="statusClick(30, false)">
  33. <view>待评价</view>
  34. <view class='num'>{{orderData.uncommentedCount || 0}}</view>
  35. </view>
  36. </view>
  37. <view class='list'>
  38. <view class='item' v-for="(order, index) in orderList" :key="index">
  39. <view @click='goOrderDetails(order.id)'>
  40. <view class='title acea-row row-between-wrapper'>
  41. <view class="acea-row row-middle">
  42. <text class="sign cart-color acea-row row-center-wrapper" v-if="order.typeName">{{ order.typeName }}</text>
  43. <view>{{ formatDate(order.createTime) }}</view>
  44. </view>
  45. <!-- 订单状态 -->
  46. <view class='font-color'>{{order.orderStatus}}</view>
  47. <view v-if="order.status === 0" class="font-color">待付款</view>
  48. <view v-else-if="order.status === 10 && order.deliveryType === 1" class="font-color">待发货</view>
  49. <!-- TODO 芋艿:核销逻辑 -->
  50. <view v-else-if="order.status === 10 && order.deliveryType === 2" class="font-color">待核销</view>
  51. <view v-else-if="order.status === 20" class="font-color">待收货</view>
  52. <view v-else-if="order.status === 30 && !order.commentStatus" class="font-color">待评价</view>
  53. <view v-else-if="order.status === 30 && order.commentStatus" class="font-color">已完成</view>
  54. <view v-else-if="order.status === 40" class="font-color">已关闭</view>
  55. </view>
  56. <!-- 订单项信息 -->
  57. <view class='item-info acea-row row-between row-top' v-for="(item, index) in order.items" :key="index">
  58. <view class='pictrue'>
  59. <image :src='item.picUrl'></image>
  60. </view>
  61. <view class='text acea-row row-between'>
  62. <view class='name line2'>{{ item.spuName }}</view>
  63. <view class='money'>
  64. <view>¥{{ fen2yuan(item.price) }}</view>
  65. <view>x{{ item.count }}</view>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 订单金额 -->
  70. <view class='totalPrice'>共{{ order.productCount }}件商品,总金额
  71. <text class='money font-color'>¥{{ fen2yuan(order.payPrice) }}</text>
  72. </view>
  73. </view>
  74. <!-- 订单操作区 -->
  75. <view class='bottom acea-row row-right row-middle'>
  76. <view class='bnt cancelBnt' v-if="order.status === 0" @click='cancelOrder(index, order.id)'>
  77. 取消订单
  78. </view>
  79. <view class='bnt bg-color' v-if="order.status === 0" @click='goPay(order.id, order.payOrderId)'>
  80. 立即付款
  81. </view>
  82. <view class='bnt bg-color' v-if="order.status === 30 && !order.commentStatus" @click='goOrderDetails(order.id)'>
  83. 去评价
  84. </view>
  85. <view class='bnt cancelBnt' v-if="order.status === 40" @click='delOrder(order.id, index)'>
  86. 删除订单
  87. </view>
  88. <view class='bnt bg-color' @click='goOrderDetails(order.id)'>
  89. 查看详情
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. <view class='loadingicon acea-row row-center-wrapper' v-if="orderList.length>0">
  95. <text class='loading iconfont icon-jiazai' :hidden='!loading' /> {{loadTitle}}
  96. </view>
  97. <view v-if="orderList.length === 0">
  98. <emptyPage title="暂无订单~"></emptyPage>
  99. </view>
  100. </view>
  101. <view class='noCart' v-if="orderList.length === 0 && page > 1">
  102. <view class='pictrue'>
  103. <image src='/images/noOrder.png'></image>
  104. </view>
  105. </view>
  106. <home></home>
  107. </view>
  108. </template>
  109. <script>
  110. import { openOrderSubscribe } from '@/utils/SubscribeMessage.js';
  111. import home from '@/components/home';
  112. import payment from '@/components/payment';
  113. import { toLogin } from '@/libs/login.js';
  114. import { mapGetters } from "vuex";
  115. import emptyPage from '@/components/emptyPage.vue'
  116. import * as OrderApi from '@/api/trade/order.js';
  117. import dayjs from '@/plugin/dayjs/dayjs.min.js';
  118. import * as Util from '@/utils/util.js';
  119. export default {
  120. components: {
  121. payment,
  122. home,
  123. emptyPage
  124. },
  125. data() {
  126. return {
  127. loading: false, //是否加载中
  128. loadend: false, //是否加载完毕
  129. loadTitle: '加载更多', //提示语
  130. orderList: [], // 订单数组
  131. orderData: {}, // 订单详细统计
  132. orderStatus: undefined, // Tab 的订单状态
  133. commentStatus: undefined, // Tab 的评论状态
  134. page: 1,
  135. limit: 20,
  136. };
  137. },
  138. computed: mapGetters(['isLogin', 'userInfo']),
  139. onShow() {
  140. if (!this.isLogin) {
  141. toLogin();
  142. return;
  143. }
  144. this.loadend = false;
  145. this.page = 1;
  146. this.$set(this, 'orderList', []);
  147. this.getOrderData();
  148. this.getOrderList();
  149. },
  150. methods: {
  151. /**
  152. * 生命周期函数--监听页面加载
  153. */
  154. onLoad: function(options) {
  155. if (options.status) {
  156. this.orderStatus = options.status;
  157. }
  158. },
  159. /**
  160. * 获取订单统计数据
  161. */
  162. getOrderData: function() {
  163. OrderApi.getOrderCount().then(res => {
  164. this.$set(this, 'orderData', res.data);
  165. })
  166. },
  167. /**
  168. * 切换类型
  169. */
  170. statusClick: function(status, commentStatus) {
  171. if (status === this.orderStatus) {
  172. return;
  173. }
  174. this.orderStatus = status;
  175. this.commentStatus = commentStatus;
  176. this.loadend = false;
  177. this.page = 1;
  178. this.$set(this, 'orderList', []);
  179. this.getOrderList();
  180. },
  181. /**
  182. * 获取订单列表
  183. */
  184. getOrderList: function() {
  185. if (this.loadend || this.loading) {
  186. return;
  187. }
  188. this.loading = true;
  189. this.loadTitle = "加载更多";
  190. OrderApi.getOrderPage({
  191. status: this.orderStatus,
  192. commentStatus: this.commentStatus,
  193. pageNo: this.page,
  194. pageSize: this.limit
  195. }).then(res => {
  196. const list = res.data.list || [];
  197. list.forEach(item => {
  198. item.typeName = item.type === 1 ? '秒杀'
  199. : item.type === 2 ? '砍价'
  200. : item.type === 3 ? '拼团' : undefined;
  201. });
  202. // 设置结束
  203. const loadend = list.length < this.limit;
  204. this.orderList = this.$util.SplitArray(list, this.orderList);
  205. this.$set(this, 'orderList', this.orderList);
  206. this.loadend = loadend;
  207. this.loading = false;
  208. this.loadTitle = loadend ? "我也是有底线的" : '加载更多';
  209. this.page = this.page + 1;
  210. }).catch(err => {
  211. this.loading = false;
  212. this.loadTitle = "加载更多";
  213. })
  214. },
  215. /**
  216. * 打开支付组件
  217. */
  218. goPay(id, payOrderId) {
  219. const returnUrl = encodeURIComponent('/pages/order_pay_status/index?order_id=' + id);
  220. uni.navigateTo({
  221. url: `/pages/goods/cashier/index?order_id=${payOrderId}&returnUrl=${returnUrl}`
  222. })
  223. },
  224. /**
  225. * 去订单详情
  226. */
  227. goOrderDetails: function(order_id) {
  228. if (!order_id) {
  229. return this.$util.Tips({
  230. title: '缺少订单号无法查看订单详情'
  231. });
  232. }
  233. // #ifdef MP
  234. uni.showLoading({
  235. title: '正在加载',
  236. })
  237. openOrderSubscribe().then(() => {
  238. uni.hideLoading();
  239. uni.navigateTo({
  240. url: '/pages/order_details/index?order_id=' + order_id
  241. })
  242. }).catch(() => {
  243. uni.hideLoading();
  244. })
  245. // #endif
  246. // #ifndef MP
  247. uni.navigateTo({
  248. url: '/pages/order_details/index?order_id=' + order_id
  249. })
  250. // #endif
  251. },
  252. /**
  253. * 取消订单
  254. */
  255. cancelOrder: function(index, order_id) {
  256. uni.showModal({
  257. title: '提示',
  258. content: '确认取消该订单?',
  259. success: res => {
  260. if (res.confirm) {
  261. OrderApi.cancelOrder(order_id).then(() => {
  262. this.$util.Tips({
  263. title: '取消成功'
  264. }, () => {
  265. this.orderList.splice(index, 1);
  266. this.$set(this, 'orderList', this.orderList);
  267. this.getOrderData();
  268. })
  269. }).catch((err) => {
  270. this.$util.Tips({
  271. title: err
  272. })
  273. });
  274. }
  275. }
  276. });
  277. },
  278. /**
  279. * 删除订单
  280. */
  281. delOrder: function(order_id, index) {
  282. uni.showModal({
  283. title: '提示',
  284. content: '确认删除该订单?',
  285. success: res => {
  286. if (res.confirm) {
  287. OrderApi.deleteOrder(order_id).then(() => {
  288. this.$util.Tips({
  289. title: '删除成功'
  290. }, () => {
  291. this.orderList.splice(index, 1);
  292. this.$set(this, 'orderList', this.orderList);
  293. this.getOrderData();
  294. })
  295. }).catch((err) => {
  296. this.$util.Tips({
  297. title: err
  298. })
  299. });
  300. }
  301. }
  302. });
  303. },
  304. fen2yuan(price) {
  305. return Util.fen2yuan(price)
  306. },
  307. formatDate: function(date) {
  308. return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
  309. }
  310. },
  311. onReachBottom: function() {
  312. this.getOrderList();
  313. }
  314. }
  315. </script>
  316. <style scoped lang="scss">
  317. .my-order .header {
  318. height: 250rpx;
  319. padding: 0 30rpx;
  320. }
  321. .my-order .header .picTxt {
  322. height: 190rpx;
  323. }
  324. .my-order .header .picTxt .text {
  325. color: rgba(255, 255, 255, 0.8);
  326. font-size: 26rpx;
  327. font-family: 'Guildford Pro';
  328. }
  329. .my-order .header .picTxt .text .name {
  330. font-size: 34rpx;
  331. font-weight: bold;
  332. color: #fff;
  333. margin-bottom: 20rpx;
  334. }
  335. .my-order .header .picTxt .pictrue {
  336. width: 122rpx;
  337. height: 109rpx;
  338. }
  339. .my-order .header .picTxt .pictrue image {
  340. width: 100%;
  341. height: 100%;
  342. }
  343. .my-order .nav {
  344. background-color: #fff;
  345. width: 690rpx;
  346. height: 140rpx;
  347. border-radius: 14rpx;
  348. margin: -60rpx auto 0 auto;
  349. }
  350. .my-order .nav .item {
  351. text-align: center;
  352. font-size: 26rpx;
  353. color: #282828;
  354. padding: 26rpx 0;
  355. }
  356. .my-order .nav .item.on {
  357. // font-weight: bold;
  358. // border-bottom: 5rpx solid #e93323;
  359. /* #ifdef H5 || MP */
  360. font-weight: bold;
  361. /* #endif */
  362. border-bottom: 5rpx solid $theme-color;
  363. }
  364. .my-order .nav .item .num {
  365. margin-top: 18rpx;
  366. }
  367. .my-order .list {
  368. width: 690rpx;
  369. margin: 14rpx auto 0 auto;
  370. }
  371. .my-order .list .item {
  372. background-color: #fff;
  373. border-radius: 14rpx;
  374. margin-bottom: 14rpx;
  375. }
  376. .my-order .list .item .title {
  377. height: 84rpx;
  378. padding: 0 24rpx;
  379. border-bottom: 1rpx solid #eee;
  380. font-size: 28rpx;
  381. color: #282828;
  382. }
  383. .my-order .list .item .title .sign {
  384. font-size: 24rpx;
  385. padding: 0 13rpx;
  386. height: 36rpx;
  387. margin-right: 15rpx;
  388. border-radius: 18rpx;
  389. }
  390. .my-order .list .item .item-info {
  391. padding: 0 24rpx;
  392. margin-top: 22rpx;
  393. }
  394. .my-order .list .item .item-info .pictrue {
  395. width: 120rpx;
  396. height: 120rpx;
  397. }
  398. .my-order .list .item .item-info .pictrue image {
  399. width: 100%;
  400. height: 100%;
  401. border-radius: 14rpx;
  402. }
  403. .my-order .list .item .item-info .text {
  404. width: 500rpx;
  405. font-size: 28rpx;
  406. color: #999;
  407. }
  408. .my-order .list .item .item-info .text .name {
  409. width: 350rpx;
  410. color: #282828;
  411. }
  412. .my-order .list .item .item-info .text .money {
  413. text-align: right;
  414. }
  415. .my-order .list .item .totalPrice {
  416. font-size: 26rpx;
  417. color: #282828;
  418. text-align: right;
  419. margin: 27rpx 0 0 30rpx;
  420. padding: 0 30rpx 30rpx 0;
  421. border-bottom: 1rpx solid #eee;
  422. }
  423. .my-order .list .item .totalPrice .money {
  424. font-size: 28rpx;
  425. font-weight: bold;
  426. }
  427. .my-order .list .item .bottom {
  428. height: 107rpx;
  429. padding: 0 30rpx;
  430. }
  431. .my-order .list .item .bottom .bnt {
  432. width: 176rpx;
  433. height: 60rpx;
  434. text-align: center;
  435. line-height: 60rpx;
  436. color: #fff;
  437. border-radius: 50rpx;
  438. font-size: 27rpx;
  439. }
  440. .my-order .list .item .bottom .bnt.cancelBnt {
  441. border: 1rpx solid #ddd;
  442. color: #aaa;
  443. }
  444. .my-order .list .item .bottom .bnt~.bnt {
  445. margin-left: 17rpx;
  446. }
  447. .noCart {
  448. margin-top: 171rpx;
  449. padding-top: 0.1rpx;
  450. }
  451. .noCart .pictrue {
  452. width: 414rpx;
  453. height: 336rpx;
  454. margin: 78rpx auto 56rpx auto;
  455. }
  456. .noCart .pictrue image {
  457. width: 100%;
  458. height: 100%;
  459. }
  460. </style>