myOrder.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <template>
  2. <view class="content">
  3. <view class="navbar">
  4. <view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  5. </view>
  6. <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
  7. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  8. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData(tabIndex)">
  9. <!-- 空白页 -->
  10. <u-empty text="暂无订单" mode="list" v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></u-empty>
  11. <!-- 订单列表 -->
  12. <view class="seller-view" :key="oderIndex" v-for="(order, oderIndex) in tabItem.orderList">
  13. <!-- 店铺名称 -->
  14. <view class="seller-info u-flex u-row-between">
  15. <view class="seller-name" @click="navigateToStore(order)">
  16. <view class="name">{{ order.storeName }}</view>
  17. </view>
  18. <view class="order-sn">{{
  19. order.orderStatus | orderStatusList
  20. }}</view>
  21. </view>
  22. <view>
  23. <view>
  24. <view class="goods-item-view" @click="navigateToOrderDetail(order.sn)">
  25. <view class="goods-img" v-for="(goods, goodsIndex) in order.orderItems" :key="goodsIndex">
  26. <u-image border-radius="6" width="100%" height="100%" :src="goods.image"></u-image>
  27. </view>
  28. <view class="goods-info">
  29. <view v-if="order.orderItems.length <= 1" class="goods-title u-line-2">{{ order.groupName }}</view>
  30. <view v-if="order.orderItems.length <= 1" class="goods-price">
  31. ¥{{ order.flowPrice | unitPrice }}
  32. </view>
  33. </view>
  34. <view v-if="order.orderItems.length <= 1" class="goods-num">
  35. <view>x{{ order.groupNum }}</view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="btn-view u-flex u-row-between">
  40. <view class="description">
  41. <!-- 等待付款 -->
  42. <text v-if="order.payStatus === 'PAID'">已付金额:</text>
  43. <text v-else>应付金额:</text>
  44. <text class="price">¥{{ order.flowPrice | unitPrice }}</text>
  45. </view>
  46. <view>
  47. <!-- 全部 -->
  48. <u-button ripple class="pay-btn" shape="circle" size="mini" v-if="order.allowOperationVO.pay" @click="waitPay(order)">立即付款</u-button>
  49. <!-- 取消订单 -->
  50. <u-button ripple class="cancel-btn" shape="circle" size="mini" v-if="order.allowOperationVO.cancel" @click="onCancel(order.sn)">
  51. 取消订单
  52. </u-button>
  53. <!-- 等待收货 -->
  54. <u-button ripple shape="circle" class="rebuy-btn" size="mini" v-if="order.allowOperationVO.showLogistics" @click="navigateToLogistics(order)">
  55. 查看物流
  56. </u-button>
  57. <u-button ripple :customStyle="{'background':lightColor,'color':'#fff' }" shape="circle" class="pay-btn" size="mini" v-if="order.allowOperationVO.rog" @click="onRog(order.sn)">
  58. 确认收货
  59. </u-button>
  60. <u-button ripple shape="circle" class="cancel-btn" size="mini" v-if="order.groupAfterSaleStatus=='NOT_APPLIED'" @click="applyService(order)">
  61. 退款/售后
  62. </u-button>
  63. <!-- TODO 后续完善 -->
  64. <!-- <u-button ripple shape="circle" class="rebuy-btn" size="mini" v-if="
  65. order.orderStatus === 'CANCELLED' ||
  66. order.orderStatus === 'COMPLETE'
  67. " @click="reBuy(order)">
  68. 再次购买
  69. </u-button> -->
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <uni-load-more :status="tabItem.loadStatus"></uni-load-more>
  75. </scroll-view>
  76. </swiper-item>
  77. </swiper>
  78. <u-popup class="cancel-popup" v-model="cancelShow" mode="bottom" length="60%">
  79. <view class="header">取消订单</view>
  80. <view class="body">
  81. <view class="title">取消订单后,本单享有的优惠可能会一并取消,是否继续?</view>
  82. <view>
  83. <u-radio-group v-model="reason">
  84. <view class="value">
  85. <view class="radio-view" :key="index" v-for="(item, index) in cancelList">
  86. <u-radio :active-color="lightColor" label-size="25" shape="circle" :name="item.reason" @change="reasonChange">{{ item.reason }}</u-radio>
  87. </view>
  88. </view>
  89. </u-radio-group>
  90. </view>
  91. </view>
  92. <view class="footer">
  93. <u-button size="medium" ripple v-if="reason" shape="circle" @click="submitCancel">提交</u-button>
  94. </view>
  95. </u-popup>
  96. <u-toast ref="uToast" />
  97. <u-modal :confirm-color="lightColor" v-model="rogShow" :show-cancel-button="true" :content="'是否确认收货?'" @confirm="confirmRog"></u-modal>
  98. </view>
  99. </template>
  100. <script>
  101. import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
  102. import { getOrderList, cancelOrder, confirmReceipt } from "@/api/order.js";
  103. import { getClearReason } from "@/api/after-sale.js";
  104. import LiLiWXPay from "@/js_sdk/lili-pay/wx-pay.js";
  105. export default {
  106. components: {
  107. uniLoadMore,
  108. },
  109. data() {
  110. return {
  111. lightColor: this.$lightColor,
  112. tabCurrentIndex: 0, //导航栏索引
  113. navList: [
  114. //导航栏list
  115. {
  116. state: 0,
  117. text: "全部",
  118. loadStatus: "more",
  119. orderList: [],
  120. pageNumber: 1,
  121. },
  122. {
  123. state: 1,
  124. text: "待付款",
  125. loadStatus: "more",
  126. orderList: [],
  127. pageNumber: 1,
  128. },
  129. {
  130. state: 2,
  131. text: "待发货",
  132. loadStatus: "more",
  133. orderList: [],
  134. pageNumber: 1,
  135. },
  136. {
  137. state: 3,
  138. text: "待收货",
  139. loadStatus: "more",
  140. orderList: [],
  141. pageNumber: 1,
  142. },
  143. {
  144. state: 4,
  145. text: "已完成",
  146. loadStatus: "more",
  147. orderList: [],
  148. pageNumber: 1,
  149. },
  150. {
  151. state: 5,
  152. text: "已取消",
  153. loadStatus: "more",
  154. orderList: [],
  155. pageNumber: 1,
  156. },
  157. ],
  158. status: "", //接收导航栏状态
  159. params: {
  160. pageNumber: 1,
  161. pageSize: 10,
  162. tag: "ALL",
  163. },
  164. orderStatus: [
  165. //订单状态
  166. {
  167. orderStatus: "ALL", //全部
  168. },
  169. {
  170. orderStatus: "WAIT_PAY", //代付款
  171. },
  172. {
  173. orderStatus: "WAIT_SHIP",
  174. },
  175. {
  176. orderStatus: "WAIT_ROG", //待收货
  177. },
  178. {
  179. orderStatus: "COMPLETE", //已完成
  180. },
  181. {
  182. orderStatus: "CANCELLED", //已取消
  183. },
  184. ],
  185. cancelShow: false, //是否显示取消
  186. orderSn: "", //ordersn
  187. reason: "", //取消原因
  188. cancelList: "", //取消列表
  189. rogShow: false, //显示是否收货
  190. };
  191. },
  192. /**
  193. * 跳转到个人中心
  194. */
  195. onBackPress(e) {
  196. if (e.from == "backbutton") {
  197. uni.reLaunch({
  198. url: "/pages/tabbar/user/my",
  199. });
  200. return true; //阻止默认返回行为
  201. }
  202. },
  203. onPullDownRefresh() {
  204. this.loadData(this.status);
  205. },
  206. onLoad(options) {
  207. /**
  208. * 修复app端点击除全部订单外的按钮进入时不加载数据的问题
  209. * 替换onLoad下代码即可
  210. */
  211. let status = Number(options.status);
  212. this.status = status;
  213. this.tabCurrentIndex = status;
  214. if (status == 0) {
  215. this.loadData(status);
  216. }
  217. },
  218. watch: {
  219. /**监听更改请求数据 */
  220. tabCurrentIndex(val) {
  221. this.params.tag = this.orderStatus[val].orderStatus;
  222. //切换标签页将所有的页数都重置为1
  223. this.navList.forEach((res) => {
  224. res.pageNumber = 1;
  225. res.loadStatus = "more";
  226. res.orderList = [];
  227. });
  228. this.loadData(val);
  229. },
  230. },
  231. methods: {
  232. // 售后
  233. applyService(order){
  234. uni.navigateTo({
  235. url: `/pages/order/afterSales/afterSales?orderSn=${order.sn}`
  236. });
  237. },
  238. // 店铺详情
  239. navigateToStore(val) {
  240. uni.navigateTo({
  241. url: "/pages/product/shopPage?id=" + val.storeId,
  242. });
  243. },
  244. /**
  245. * 取消订单
  246. */
  247. onCancel(sn) {
  248. this.orderSn = sn;
  249. this.cancelShow = true;
  250. uni.showLoading({
  251. title: "加载中",
  252. });
  253. getClearReason().then((res) => {
  254. if (res.data.result.length >= 1) {
  255. this.cancelList = res.data.result;
  256. }
  257. uni.hideLoading();
  258. });
  259. },
  260. /**
  261. * 初始化数据
  262. */
  263. initData(index) {
  264. this.navList[index].pageNumber = 1;
  265. this.navList[index].loadStatus = "more";
  266. this.navList[index].orderList = [];
  267. this.loadData(index);
  268. },
  269. /**
  270. * 等待支付
  271. */
  272. waitPay(val) {
  273. this.$u.debounce(this.pay(val), 3000);
  274. },
  275. /**
  276. * 支付
  277. */
  278. pay(val) {
  279. if (val.sn) {
  280. // #ifdef MP-WEIXIN
  281. new LiLiWXPay({
  282. sn: val.sn,
  283. price: val.flowPrice,
  284. orderType: "ORDER",
  285. }).pay();
  286. // #endif
  287. // #ifndef MP-WEIXIN
  288. uni.navigateTo({
  289. url: "/pages/cart/payment/payOrder?order_sn=" + val.sn,
  290. });
  291. // #endif
  292. }
  293. },
  294. /**
  295. * 获取订单列表
  296. */
  297. loadData(index) {
  298. this.params.pageNumber = this.navList[index].pageNumber;
  299. getOrderList(this.params).then((res) => {
  300. uni.stopPullDownRefresh();
  301. if (!res.data.success) {
  302. this.navList[index].loadStatus = "noMore";
  303. return false;
  304. }
  305. let orderList = res.data.result.records;
  306. if (orderList.length == 0) {
  307. this.navList[index].loadStatus = "noMore";
  308. } else if (orderList.length < 10) {
  309. this.navList[index].loadStatus = "noMore";
  310. }
  311. if (orderList.length > 0) {
  312. this.navList[index].orderList =
  313. this.navList[index].orderList.concat(orderList);
  314. this.navList[index].pageNumber += 1;
  315. }
  316. });
  317. },
  318. //swiper 切换监听
  319. changeTab(e) {
  320. this.tabCurrentIndex = e.target.current;
  321. },
  322. //顶部tab点击
  323. tabClick(index) {
  324. this.tabCurrentIndex = index;
  325. },
  326. //删除订单
  327. deleteOrder(index) {
  328. uni.showLoading({
  329. title: "请稍后",
  330. });
  331. setTimeout(() => {
  332. this.navList[this.tabCurrentIndex].orderList.splice(index, 1);
  333. uni.hideLoading();
  334. }, 600);
  335. },
  336. //取消订单
  337. cancelOrder(item) {
  338. uni.showLoading({
  339. title: "请稍后",
  340. });
  341. setTimeout(() => {
  342. let { stateTip, stateTipColor } = this.orderStateExp(9);
  343. item = Object.assign(item, {
  344. state: 9,
  345. stateTip,
  346. stateTipColor,
  347. });
  348. //取消订单后删除待付款中该项
  349. let list = this.navList[1].orderList;
  350. let index = list.findIndex((val) => val.id === item.id);
  351. index !== -1 && list.splice(index, 1);
  352. uni.hideLoading();
  353. }, 600);
  354. },
  355. //订单状态文字和颜色
  356. orderStateExp(state) {
  357. let stateTip = "",
  358. stateTipColor = this.$lightColor;
  359. switch (+state) {
  360. case 1:
  361. stateTip = "待付款";
  362. break;
  363. case 2:
  364. stateTip = "待发货";
  365. break;
  366. case 9:
  367. stateTip = "订单已关闭";
  368. stateTipColor = "#909399";
  369. break;
  370. //更多自定义
  371. }
  372. return {
  373. stateTip,
  374. stateTipColor,
  375. };
  376. },
  377. /**
  378. * 跳转到订单详情
  379. */
  380. navigateToOrderDetail(sn) {
  381. uni.navigateTo({
  382. url: "./orderDetail?sn=" + sn,
  383. });
  384. },
  385. /**
  386. * 选择取消原因
  387. */
  388. reasonChange(reason) {
  389. this.reason = reason;
  390. },
  391. /**
  392. * 提交取消订单(未付款)
  393. */
  394. submitCancel() {
  395. cancelOrder(this.orderSn, { reason: this.reason }).then((res) => {
  396. if (res.statusCode == 200) {
  397. uni.showToast({
  398. title: "订单已取消",
  399. duration: 2000,
  400. icon: "none",
  401. });
  402. this.initData(0);
  403. this.cancelShow = false;
  404. } else {
  405. uni.showToast({
  406. title: res.data.message,
  407. duration: 2000,
  408. icon: "none",
  409. });
  410. this.cancelShow = false;
  411. }
  412. });
  413. },
  414. /**
  415. * 确认收货显示
  416. */
  417. onRog(sn) {
  418. this.orderSn = sn;
  419. this.rogShow = true;
  420. },
  421. /**
  422. * 点击确认收货
  423. */
  424. confirmRog() {
  425. confirmReceipt(this.orderSn).then((res) => {
  426. if (res.data.code == 200) {
  427. uni.showToast({
  428. title: "已确认收货",
  429. duration: 2000,
  430. icon: "none",
  431. });
  432. this.initData(this.tabCurrentIndex);
  433. this.rogShow = false;
  434. }
  435. });
  436. },
  437. /**
  438. * 评价商品
  439. */
  440. onComment(sn) {
  441. uni.navigateTo({
  442. url: "./evaluate/myEvaluate",
  443. });
  444. },
  445. /**
  446. * 重新购买
  447. */
  448. reBuy(order) {
  449. console.log(order);
  450. return;
  451. uni.navigateTo({
  452. url:
  453. "/pages/product/goods?id=" + order.id + "&goodsId=" + order.goodsId,
  454. });
  455. },
  456. /**
  457. * 查看物流
  458. */
  459. navigateToLogistics(order) {
  460. uni.navigateTo({
  461. url:
  462. "/pages/mine/msgTips/packageMsg/logisticsDetail?order_sn=" + order.sn,
  463. });
  464. },
  465. },
  466. };
  467. </script>
  468. <style lang="scss" scoped>
  469. page,
  470. .content {
  471. background: $page-color-base;
  472. height: 100%;
  473. }
  474. .swiper-box {
  475. height: calc(100vh - 40px);
  476. }
  477. .list-scroll-content {
  478. height: 100%;
  479. }
  480. .navbar {
  481. display: flex;
  482. height: 40px;
  483. padding: 0 5px;
  484. background: #fff;
  485. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  486. position: relative;
  487. z-index: 10;
  488. .nav-item {
  489. flex: 1;
  490. display: flex;
  491. justify-content: center;
  492. align-items: center;
  493. height: 100%;
  494. font-size: 26rpx;
  495. color: $font-color-light;
  496. position: relative;
  497. &.current {
  498. color: $main-color;
  499. &:after {
  500. content: "";
  501. position: absolute;
  502. left: 50%;
  503. bottom: 0;
  504. transform: translateX(-50%);
  505. width: 44px;
  506. height: 0;
  507. border-bottom: 2px solid $main-color;
  508. }
  509. }
  510. }
  511. }
  512. .uni-swiper-item {
  513. height: auto;
  514. }
  515. .seller-view {
  516. border-radius: 20rpx;
  517. background-color: #fff;
  518. margin: 20rpx 0rpx;
  519. .seller-info {
  520. height: 70rpx;
  521. padding: 0 20rpx;
  522. .seller-name {
  523. font-size: 28rpx;
  524. font-weight: 600;
  525. display: flex;
  526. flex-direction: row;
  527. .name {
  528. margin-left: 15rpx;
  529. margin-top: -2rpx;
  530. }
  531. }
  532. .order-sn {
  533. color: $aider-light-color;
  534. font-size: 26rpx;
  535. }
  536. }
  537. .goods-item-view {
  538. display: flex;
  539. flex-wrap: wrap;
  540. flex-direction: row;
  541. padding: 10rpx 20rpx;
  542. .goods-img {
  543. width: 131rpx;
  544. height: 131rpx;
  545. margin-right: 10rpx;
  546. margin-bottom: 10rpx;
  547. }
  548. .goods-info {
  549. padding-left: 30rpx;
  550. flex: 1;
  551. .goods-title {
  552. margin-bottom: 10rpx;
  553. color: #333333;
  554. }
  555. .goods-specs {
  556. font-size: 24rpx;
  557. margin-bottom: 10rpx;
  558. color: #cccccc;
  559. }
  560. .goods-price {
  561. font-size: 28rpx;
  562. margin-bottom: 10rpx;
  563. color: $aider-light-color;
  564. }
  565. }
  566. .goods-num {
  567. width: 60rpx;
  568. color: $main-color;
  569. }
  570. }
  571. .btn-view {
  572. padding: 25rpx 30rpx;
  573. font-size: 26rpx;
  574. .description {
  575. color: #909399;
  576. size: 25rpx;
  577. .price {
  578. color: $main-color;
  579. }
  580. }
  581. }
  582. }
  583. .cancel-popup {
  584. .header {
  585. display: flex;
  586. flex-direction: row;
  587. justify-content: center;
  588. margin: 15rpx 0rpx;
  589. }
  590. .body {
  591. padding: 30rpx;
  592. .title {
  593. font-weight: 600;
  594. }
  595. .value {
  596. display: flex;
  597. flex-direction: column;
  598. margin: 20rpx 0;
  599. .radio-view {
  600. margin: 20rpx 0rpx;
  601. }
  602. }
  603. }
  604. .footer {
  605. text-align: center;
  606. }
  607. }
  608. .cancel-btn {
  609. color: #999999 !important;
  610. border-color: #999999 !important;
  611. margin-left: 15rpx;
  612. height: 60rpx;
  613. }
  614. .pay-btn {
  615. // #ifndef MP-WEIXIN
  616. background-color: $light-color !important;
  617. // #endif
  618. color: #ffffff !important;
  619. margin-left: 15rpx;
  620. height: 60rpx;
  621. }
  622. .rebuy-btn {
  623. color: $light-color !important;
  624. border-color: $light-color !important;
  625. background-color: #ffffff !important;
  626. margin-left: 15rpx;
  627. height: 60rpx;
  628. }
  629. </style>