myOrder.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></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="rebuy-btn" size="mini" v-if="
  61. order.orderStatus === 'CANCELLED' ||
  62. order.orderStatus === 'COMPLETE'
  63. " @click="reBuy(order)">
  64. 再次购买
  65. </u-button>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="nodata" v-if="tabItem.loadStatus === 'noMore'">
  71. </view>
  72. <uni-load-more :status="tabItem.loadStatus"></uni-load-more>
  73. </scroll-view>
  74. </swiper-item>
  75. </swiper>
  76. <u-popup class="cancel-popup" v-model="cancelShow" mode="bottom" length="60%">
  77. <view class="header">取消订单</view>
  78. <view class="body">
  79. <view class="title">取消订单后,本单享有的优惠可能会一并取消,是否继续?</view>
  80. <view>
  81. <u-radio-group v-model="reason">
  82. <view class="value">
  83. <view class="radio-view" :key="index" v-for="(item, index) in cancelList">
  84. <u-radio :active-color="lightColor" label-size="25" shape="circle" :name="item.reason" @change="reasonChange">{{ item.reason }}</u-radio>
  85. </view>
  86. </view>
  87. </u-radio-group>
  88. </view>
  89. </view>
  90. <view class="footer">
  91. <u-button size="medium" ripple v-if="reason" shape="circle" @click="submitCancel">提交</u-button>
  92. </view>
  93. </u-popup>
  94. <u-toast ref="uToast" />
  95. <u-modal :confirm-color="lightColor" v-model="rogShow" :show-cancel-button="true" :content="'是否确认收货?'" @confirm="confirmRog"></u-modal>
  96. </view>
  97. </template>
  98. <script>
  99. import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
  100. import empty from "@/components/empty";
  101. import { getOrderList, cancelOrder, confirmReceipt } from "@/api/order.js";
  102. import { getClearReason } from "@/api/after-sale.js";
  103. import LiLiWXPay from "@/js_sdk/lili-pay/wx-pay.js";
  104. export default {
  105. components: {
  106. uniLoadMore,
  107. empty,
  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. navigateToStore(val) {
  234. uni.navigateTo({
  235. url: "/pages/product/shopPage?id=" + val.storeId,
  236. });
  237. },
  238. /**
  239. * 取消订单
  240. */
  241. onCancel(sn) {
  242. this.orderSn = sn;
  243. this.cancelShow = true;
  244. uni.showLoading({
  245. title: "加载中",
  246. });
  247. getClearReason().then((res) => {
  248. if (res.data.result.length >= 1) {
  249. this.cancelList = res.data.result;
  250. }
  251. uni.hideLoading();
  252. });
  253. },
  254. /**
  255. * 初始化数据
  256. */
  257. initData(index) {
  258. this.navList[index].pageNumber = 1;
  259. this.navList[index].loadStatus = "more";
  260. this.navList[index].orderList = [];
  261. this.loadData(index);
  262. },
  263. /**
  264. * 等待支付
  265. */
  266. waitPay(val) {
  267. this.$u.debounce(this.pay(val), 3000);
  268. },
  269. /**
  270. * 支付
  271. */
  272. pay(val) {
  273. if (val.sn) {
  274. // #ifdef MP-WEIXIN
  275. new LiLiWXPay({
  276. sn: val.sn,
  277. price: val.flowPrice,
  278. orderType: "ORDER",
  279. }).pay();
  280. // #endif
  281. // #ifndef MP-WEIXIN
  282. uni.navigateTo({
  283. url: "/pages/cart/payment/payOrder?order_sn=" + val.sn,
  284. });
  285. // #endif
  286. }
  287. },
  288. /**
  289. * 获取订单列表
  290. */
  291. loadData(index) {
  292. this.params.pageNumber = this.navList[index].pageNumber;
  293. getOrderList(this.params).then((res) => {
  294. uni.stopPullDownRefresh();
  295. if (!res.data.success) {
  296. this.navList[index].loadStatus = "noMore";
  297. return false;
  298. }
  299. let orderList = res.data.result.records;
  300. if (orderList.length == 0) {
  301. this.navList[index].loadStatus = "noMore";
  302. } else if (orderList.length < 10) {
  303. this.navList[index].loadStatus = "noMore";
  304. }
  305. if (orderList.length > 0) {
  306. this.navList[index].orderList = this.navList[index].orderList.concat(
  307. orderList
  308. );
  309. this.navList[index].pageNumber += 1;
  310. }
  311. });
  312. },
  313. //swiper 切换监听
  314. changeTab(e) {
  315. this.tabCurrentIndex = e.target.current;
  316. },
  317. //顶部tab点击
  318. tabClick(index) {
  319. this.tabCurrentIndex = index;
  320. },
  321. //删除订单
  322. deleteOrder(index) {
  323. uni.showLoading({
  324. title: "请稍后",
  325. });
  326. setTimeout(() => {
  327. this.navList[this.tabCurrentIndex].orderList.splice(index, 1);
  328. uni.hideLoading();
  329. }, 600);
  330. },
  331. //取消订单
  332. cancelOrder(item) {
  333. uni.showLoading({
  334. title: "请稍后",
  335. });
  336. setTimeout(() => {
  337. let { stateTip, stateTipColor } = this.orderStateExp(9);
  338. item = Object.assign(item, {
  339. state: 9,
  340. stateTip,
  341. stateTipColor,
  342. });
  343. //取消订单后删除待付款中该项
  344. let list = this.navList[1].orderList;
  345. let index = list.findIndex((val) => val.id === item.id);
  346. index !== -1 && list.splice(index, 1);
  347. uni.hideLoading();
  348. }, 600);
  349. },
  350. //订单状态文字和颜色
  351. orderStateExp(state) {
  352. let stateTip = "",
  353. stateTipColor = this.$lightColor;
  354. switch (+state) {
  355. case 1:
  356. stateTip = "待付款";
  357. break;
  358. case 2:
  359. stateTip = "待发货";
  360. break;
  361. case 9:
  362. stateTip = "订单已关闭";
  363. stateTipColor = "#909399";
  364. break;
  365. //更多自定义
  366. }
  367. return {
  368. stateTip,
  369. stateTipColor,
  370. };
  371. },
  372. /**
  373. * 跳转到订单详情
  374. */
  375. navigateToOrderDetail(sn) {
  376. uni.navigateTo({
  377. url: "./orderDetail?sn=" + sn,
  378. });
  379. },
  380. /**
  381. * 选择取消原因
  382. */
  383. reasonChange(reason) {
  384. this.reason = reason;
  385. },
  386. /**
  387. * 提交取消订单(未付款)
  388. */
  389. submitCancel() {
  390. cancelOrder(this.orderSn, { reason: this.reason }).then((res) => {
  391. if (res.statusCode == 200) {
  392. uni.showToast({
  393. title: "订单已取消",
  394. duration: 2000,
  395. icon: "none",
  396. });
  397. this.initData(0);
  398. this.cancelShow = false;
  399. } else {
  400. uni.showToast({
  401. title: res.data.message,
  402. duration: 2000,
  403. icon: "none",
  404. });
  405. this.cancelShow = false;
  406. }
  407. });
  408. },
  409. /**
  410. * 确认收货显示
  411. */
  412. onRog(sn) {
  413. this.orderSn = sn;
  414. this.rogShow = true;
  415. },
  416. /**
  417. * 点击确认收货
  418. */
  419. confirmRog() {
  420. confirmReceipt(this.orderSn).then((res) => {
  421. if (res.data.code == 200) {
  422. uni.showToast({
  423. title: "已确认收货",
  424. duration: 2000,
  425. icon: "none",
  426. });
  427. this.initData(this.tabCurrentIndex);
  428. this.rogShow = false;
  429. }
  430. });
  431. },
  432. /**
  433. * 评价商品
  434. */
  435. onComment(sn) {
  436. uni.navigateTo({
  437. url: "./evaluate/myEvaluate",
  438. });
  439. },
  440. /**
  441. * 重新购买
  442. */
  443. reBuy(order) {
  444. uni.navigateTo({
  445. url:
  446. "/pages/product/goods?id=" +
  447. order.groupSkuId +
  448. "&goodsId=" +
  449. order.goodsId,
  450. });
  451. },
  452. /**
  453. * 查看物流
  454. */
  455. navigateToLogistics(order) {
  456. uni.navigateTo({
  457. url:
  458. "/pages/mine/msgTips/packageMsg/logisticsDetail?order_sn=" + order.sn,
  459. });
  460. },
  461. },
  462. };
  463. </script>
  464. <style lang="scss" scoped>
  465. page,
  466. .content {
  467. background: $page-color-base;
  468. height: 100%;
  469. }
  470. .swiper-box {
  471. height: calc(100vh - 40px);
  472. }
  473. .list-scroll-content {
  474. height: 100%;
  475. }
  476. .navbar {
  477. display: flex;
  478. height: 40px;
  479. padding: 0 5px;
  480. background: #fff;
  481. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  482. position: relative;
  483. z-index: 10;
  484. .nav-item {
  485. flex: 1;
  486. display: flex;
  487. justify-content: center;
  488. align-items: center;
  489. height: 100%;
  490. font-size: 26rpx;
  491. color: $font-color-light;
  492. position: relative;
  493. &.current {
  494. color: $main-color;
  495. &:after {
  496. content: "";
  497. position: absolute;
  498. left: 50%;
  499. bottom: 0;
  500. transform: translateX(-50%);
  501. width: 44px;
  502. height: 0;
  503. border-bottom: 2px solid $main-color;
  504. }
  505. }
  506. }
  507. }
  508. .uni-swiper-item {
  509. height: auto;
  510. }
  511. .seller-view {
  512. border-radius: 20rpx;
  513. background-color: #fff;
  514. margin: 20rpx 0rpx;
  515. .seller-info {
  516. height: 70rpx;
  517. padding: 0 20rpx;
  518. .seller-name {
  519. font-size: 28rpx;
  520. font-weight: 600;
  521. display: flex;
  522. flex-direction: row;
  523. .name {
  524. margin-left: 15rpx;
  525. margin-top: -2rpx;
  526. }
  527. }
  528. .order-sn {
  529. color: $aider-light-color;
  530. font-size: 26rpx;
  531. }
  532. }
  533. .goods-item-view {
  534. display: flex;
  535. flex-wrap: wrap;
  536. flex-direction: row;
  537. padding: 10rpx 20rpx;
  538. .goods-img {
  539. width: 131rpx;
  540. height: 131rpx;
  541. margin-right: 10rpx;
  542. margin-bottom: 10rpx;
  543. }
  544. .goods-info {
  545. padding-left: 30rpx;
  546. flex: 1;
  547. .goods-title {
  548. margin-bottom: 10rpx;
  549. color: #333333;
  550. }
  551. .goods-specs {
  552. font-size: 24rpx;
  553. margin-bottom: 10rpx;
  554. color: #cccccc;
  555. }
  556. .goods-price {
  557. font-size: 28rpx;
  558. margin-bottom: 10rpx;
  559. color: $aider-light-color;
  560. }
  561. }
  562. .goods-num {
  563. width: 60rpx;
  564. color: $main-color;
  565. }
  566. }
  567. .btn-view {
  568. padding: 25rpx 30rpx;
  569. font-size: 26rpx;
  570. .description {
  571. color: #909399;
  572. size: 25rpx;
  573. .price {
  574. color: $main-color;
  575. }
  576. }
  577. }
  578. }
  579. .cancel-popup {
  580. .header {
  581. display: flex;
  582. flex-direction: row;
  583. justify-content: center;
  584. margin: 15rpx 0rpx;
  585. }
  586. .body {
  587. padding: 30rpx;
  588. .title {
  589. font-weight: 600;
  590. }
  591. .value {
  592. display: flex;
  593. flex-direction: column;
  594. margin: 20rpx 0;
  595. .radio-view {
  596. margin: 20rpx 0rpx;
  597. }
  598. }
  599. }
  600. .footer {
  601. text-align: center;
  602. }
  603. }
  604. .cancel-btn {
  605. color: #999999 !important;
  606. border-color: #999999 !important;
  607. margin-left: 15rpx;
  608. height: 60rpx;
  609. }
  610. .pay-btn {
  611. // #ifndef MP-WEIXIN
  612. background-color: $light-color !important;
  613. // #endif
  614. color: #ffffff !important;
  615. margin-left: 15rpx;
  616. height: 60rpx;
  617. }
  618. .rebuy-btn {
  619. color: $light-color !important;
  620. border-color: $light-color !important;
  621. background-color: #ffffff !important;
  622. margin-left: 15rpx;
  623. height: 60rpx;
  624. }
  625. .nodata {
  626. // padding-top: 300rpx;
  627. color: #999999;
  628. text-align: center;
  629. img {
  630. width: 346rpx;
  631. height: 304rpx;
  632. }
  633. }
  634. </style>