myOrder.vue 17 KB

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