index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. console.log(status, this.orderStatus,'status === this.orderStatus')
  172. if (status === this.orderStatus) {
  173. return;
  174. }
  175. this.orderStatus = status;
  176. this.commentStatus = commentStatus;
  177. this.loadend = false;
  178. this.page = 1;
  179. this.$set(this, 'orderList', []);
  180. this.getOrderList();
  181. },
  182. /**
  183. * 获取订单列表
  184. */
  185. getOrderList: function() {
  186. if (this.loadend || this.loading) {
  187. return;
  188. }
  189. this.loading = true;
  190. this.loadTitle = "加载更多";
  191. OrderApi.getOrderPage({
  192. status: this.orderStatus,
  193. commentStatus: this.commentStatus,
  194. pageNo: this.page,
  195. pageSize: this.limit
  196. }).then(res => {
  197. const list = res.data.list || [];
  198. list.forEach(item => {
  199. item.typeName = item.type === 1 ? '秒杀'
  200. : item.type === 2 ? '砍价'
  201. : item.type === 3 ? '拼团' : undefined;
  202. });
  203. // 设置结束
  204. const loadend = list.length < this.limit;
  205. this.orderList = this.$util.SplitArray(list, this.orderList);
  206. this.$set(this, 'orderList', this.orderList);
  207. this.loadend = loadend;
  208. this.loading = false;
  209. this.loadTitle = loadend ? "我也是有底线的" : '加载更多';
  210. this.page = this.page + 1;
  211. }).catch(err => {
  212. this.loading = false;
  213. this.loadTitle = "加载更多";
  214. })
  215. },
  216. /**
  217. * 打开支付组件
  218. */
  219. goPay(id, payOrderId) {
  220. const returnUrl = encodeURIComponent('/pages/order_pay_status/index?order_id=' + id);
  221. uni.navigateTo({
  222. url: `/pages/goods/cashier/index?order_id=${payOrderId}&returnUrl=${returnUrl}`
  223. })
  224. },
  225. /**
  226. * 去订单详情
  227. */
  228. goOrderDetails: function(order_id) {
  229. if (!order_id) {
  230. return this.$util.Tips({
  231. title: '缺少订单号无法查看订单详情'
  232. });
  233. }
  234. // #ifdef MP
  235. uni.showLoading({
  236. title: '正在加载',
  237. })
  238. openOrderSubscribe().then(() => {
  239. uni.hideLoading();
  240. uni.navigateTo({
  241. url: '/pages/order_details/index?order_id=' + order_id
  242. })
  243. }).catch(() => {
  244. uni.hideLoading();
  245. })
  246. // #endif
  247. // #ifndef MP
  248. uni.navigateTo({
  249. url: '/pages/order_details/index?order_id=' + order_id
  250. })
  251. // #endif
  252. },
  253. /**
  254. * 取消订单
  255. */
  256. cancelOrder: function(index, order_id) {
  257. uni.showModal({
  258. title: '提示',
  259. content: '确认取消该订单?',
  260. success: res => {
  261. if (res.confirm) {
  262. OrderApi.cancelOrder(order_id).then(() => {
  263. this.$util.Tips({
  264. title: '取消成功'
  265. }, () => {
  266. this.orderList.splice(index, 1);
  267. this.$set(this, 'orderList', this.orderList);
  268. this.getOrderData();
  269. })
  270. }).catch((err) => {
  271. this.$util.Tips({
  272. title: err
  273. })
  274. });
  275. }
  276. }
  277. });
  278. },
  279. /**
  280. * 删除订单
  281. */
  282. delOrder: function(order_id, index) {
  283. uni.showModal({
  284. title: '提示',
  285. content: '确认删除该订单?',
  286. success: res => {
  287. if (res.confirm) {
  288. OrderApi.deleteOrder(order_id).then(() => {
  289. this.$util.Tips({
  290. title: '删除成功'
  291. }, () => {
  292. this.orderList.splice(index, 1);
  293. this.$set(this, 'orderList', this.orderList);
  294. this.getOrderData();
  295. })
  296. }).catch((err) => {
  297. this.$util.Tips({
  298. title: err
  299. })
  300. });
  301. }
  302. }
  303. });
  304. },
  305. fen2yuan(price) {
  306. return Util.fen2yuan(price)
  307. },
  308. formatDate: function(date) {
  309. return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
  310. }
  311. },
  312. onReachBottom: function() {
  313. this.getOrderList();
  314. }
  315. }
  316. </script>
  317. <style scoped lang="scss">
  318. .my-order .header {
  319. height: 250rpx;
  320. padding: 0 30rpx;
  321. }
  322. .my-order .header .picTxt {
  323. height: 190rpx;
  324. }
  325. .my-order .header .picTxt .text {
  326. color: rgba(255, 255, 255, 0.8);
  327. font-size: 26rpx;
  328. font-family: 'Guildford Pro';
  329. }
  330. .my-order .header .picTxt .text .name {
  331. font-size: 34rpx;
  332. font-weight: bold;
  333. color: #fff;
  334. margin-bottom: 20rpx;
  335. }
  336. .my-order .header .picTxt .pictrue {
  337. width: 122rpx;
  338. height: 109rpx;
  339. }
  340. .my-order .header .picTxt .pictrue image {
  341. width: 100%;
  342. height: 100%;
  343. }
  344. .my-order .nav {
  345. background-color: #fff;
  346. width: 690rpx;
  347. height: 140rpx;
  348. border-radius: 14rpx;
  349. margin: -60rpx auto 0 auto;
  350. }
  351. .my-order .nav .item {
  352. text-align: center;
  353. font-size: 26rpx;
  354. color: #282828;
  355. padding: 26rpx 0;
  356. }
  357. .my-order .nav .item.on {
  358. // font-weight: bold;
  359. // border-bottom: 5rpx solid #e93323;
  360. /* #ifdef H5 || MP */
  361. font-weight: bold;
  362. /* #endif */
  363. border-bottom: 5rpx solid $theme-color;
  364. }
  365. .my-order .nav .item .num {
  366. margin-top: 18rpx;
  367. }
  368. .my-order .list {
  369. width: 690rpx;
  370. margin: 14rpx auto 0 auto;
  371. }
  372. .my-order .list .item {
  373. background-color: #fff;
  374. border-radius: 14rpx;
  375. margin-bottom: 14rpx;
  376. }
  377. .my-order .list .item .title {
  378. height: 84rpx;
  379. padding: 0 24rpx;
  380. border-bottom: 1rpx solid #eee;
  381. font-size: 28rpx;
  382. color: #282828;
  383. }
  384. .my-order .list .item .title .sign {
  385. font-size: 24rpx;
  386. padding: 0 13rpx;
  387. height: 36rpx;
  388. margin-right: 15rpx;
  389. border-radius: 18rpx;
  390. }
  391. .my-order .list .item .item-info {
  392. padding: 0 24rpx;
  393. margin-top: 22rpx;
  394. }
  395. .my-order .list .item .item-info .pictrue {
  396. width: 120rpx;
  397. height: 120rpx;
  398. }
  399. .my-order .list .item .item-info .pictrue image {
  400. width: 100%;
  401. height: 100%;
  402. border-radius: 14rpx;
  403. }
  404. .my-order .list .item .item-info .text {
  405. width: 500rpx;
  406. font-size: 28rpx;
  407. color: #999;
  408. }
  409. .my-order .list .item .item-info .text .name {
  410. width: 350rpx;
  411. color: #282828;
  412. }
  413. .my-order .list .item .item-info .text .money {
  414. text-align: right;
  415. }
  416. .my-order .list .item .totalPrice {
  417. font-size: 26rpx;
  418. color: #282828;
  419. text-align: right;
  420. margin: 27rpx 0 0 30rpx;
  421. padding: 0 30rpx 30rpx 0;
  422. border-bottom: 1rpx solid #eee;
  423. }
  424. .my-order .list .item .totalPrice .money {
  425. font-size: 28rpx;
  426. font-weight: bold;
  427. }
  428. .my-order .list .item .bottom {
  429. height: 107rpx;
  430. padding: 0 30rpx;
  431. }
  432. .my-order .list .item .bottom .bnt {
  433. width: 176rpx;
  434. height: 60rpx;
  435. text-align: center;
  436. line-height: 60rpx;
  437. color: #fff;
  438. border-radius: 50rpx;
  439. font-size: 27rpx;
  440. }
  441. .my-order .list .item .bottom .bnt.cancelBnt {
  442. border: 1rpx solid #ddd;
  443. color: #aaa;
  444. }
  445. .my-order .list .item .bottom .bnt~.bnt {
  446. margin-left: 17rpx;
  447. }
  448. .noCart {
  449. margin-top: 171rpx;
  450. padding-top: 0.1rpx;
  451. }
  452. .noCart .pictrue {
  453. width: 414rpx;
  454. height: 336rpx;
  455. margin: 78rpx auto 56rpx auto;
  456. }
  457. .noCart .pictrue image {
  458. width: 100%;
  459. height: 100%;
  460. }
  461. </style>