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