index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <template>
  2. <view>
  3. <nav-bar title="我的订单"></nav-bar>
  4. <view
  5. style="
  6. width: 100%;
  7. text-align: center;
  8. position: fixed;
  9. height: 96rpx;
  10. z-index: 999;
  11. "
  12. >
  13. <u-tabs
  14. :list="list"
  15. sticky
  16. :current="current"
  17. @change="change"
  18. active-color="#007AFF"
  19. :offset="[-1, 0]"
  20. ></u-tabs>
  21. </view>
  22. <view style="padding: 96rpx 8rpx 96rpx">
  23. <view v-if="!order.length" class="noData">您暂无相关订单哦~</view>
  24. <template v-else>
  25. <view v-for="(item, index) in order" :key="index" class="lisChild">
  26. <view class="item">
  27. <view class="header" @click="openPopup(index)">
  28. <view>订单编号:{{ item.orderSn }}</view>
  29. <view>{{ $method.timestampToTime(item.createTime) }}</view>
  30. </view>
  31. <u-line color="#D6D6DB" />
  32. <view v-if="current == 3">
  33. <view class="body">
  34. <view class="body__content">
  35. <image
  36. class="goods-img"
  37. :src="$method.splitImgHost(item.coverUrl)"
  38. ></image>
  39. <view class="goods-text">
  40. <view class="goods-name">{{ item.goodsName }}</view>
  41. <!-- <view class="goods-price">¥ {{ items.goodsRealPrice }}</view> -->
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view v-else>
  47. <view
  48. class="body"
  49. v-for="(items, indexs) in item.orderGoodsList"
  50. :key="indexs"
  51. @click="goCourse(items, item.orderStatus)"
  52. >
  53. <view class="body__content">
  54. <image
  55. class="goods-img"
  56. :src="$method.splitImgHost(items.coverUrl)"
  57. ></image>
  58. <view class="goods-text">
  59. <view class="goods-name">{{ items.goodsName }}</view>
  60. <view class="goods-price"
  61. >¥ {{ items.goodsRealPrice }}</view
  62. >
  63. </view>
  64. </view>
  65. <view
  66. style="
  67. display: flex;
  68. flex-direction: row-reverse;
  69. padding: 10rpx 0;
  70. "
  71. >
  72. <view
  73. class="btn2"
  74. v-if="
  75. items.refundStatus === 0 &&
  76. (item.orderFrom === 2 || item.orderFrom === 3) &&
  77. (item.orderStatus === 1 ||
  78. item.orderStatus === 2 ||
  79. item.orderStatus === 3) &&
  80. (items.goodsType == '1' ||
  81. items.goodsType == '2' ||
  82. items.goodsType == '6') &&
  83. items.goodsPrice > 0
  84. "
  85. @click.stop="refund(item.orderSn, items.goodsId)"
  86. >退款</view
  87. >
  88. <view v-if="items.refundStatus == 2"> 已退款</view>
  89. </view>
  90. </view>
  91. </view>
  92. <u-line color="#D6D6DB" />
  93. <view class="footer" v-if="current == 3">
  94. <view>
  95. <text style="color: #999; font-size: 24rpx; margin-right: 8rpx"
  96. >退款金额</text
  97. >
  98. <text
  99. style="color: #ff2d55; font-size: 30rpx; font-weight: bold"
  100. >¥{{ item.refundFee }}</text
  101. >
  102. </view>
  103. </view>
  104. <view class="footer" v-else>
  105. <view>
  106. <text style="color: #999; font-size: 24rpx; margin-right: 8rpx"
  107. >共{{ item.orderGoodsList.length }}项</text
  108. >
  109. <text style="color: #333; font-size: 30rpx; font-weight: bold"
  110. >合计</text
  111. >
  112. <text
  113. style="color: #ff2d55; font-size: 30rpx; font-weight: bold"
  114. >¥{{ item.payPrice }}</text
  115. >
  116. </view>
  117. <view style="display: flex; align-items: center">
  118. <view
  119. class="btn2"
  120. v-if="
  121. item.orderStatus === 0 &&
  122. (item.orderFrom === 2 || item.orderFrom === 3)
  123. "
  124. @click="resumeOrder(item)"
  125. >继续支付</view
  126. >
  127. <!-- <view class="btn2" v-if="item.orderStatus === -1 || item.orderStatus === -2" @click="againBuy(item)">重新购买</view> -->
  128. <view
  129. class="btn1"
  130. v-if="
  131. (item.orderStatus === -1 || item.orderStatus === -2) &&
  132. (item.orderFrom === 2 || item.orderFrom === 3)
  133. "
  134. @click="delOrder(item)"
  135. >删除订单</view
  136. >
  137. <view
  138. class="btn1"
  139. @click="closeOrder(item)"
  140. v-if="
  141. item.orderStatus === 0 &&
  142. (item.orderFrom === 2 || item.orderFrom === 3)
  143. "
  144. >取消订单</view
  145. >
  146. </view>
  147. </view>
  148. </view>
  149. </view>
  150. </template>
  151. <template v-if="current == 1 && order.length">
  152. <view class="apply-invoice" @click="goInvoice">发票申请</view>
  153. </template>
  154. </view>
  155. </view>
  156. </template>
  157. <script>
  158. import { mapGetters } from "vuex";
  159. export default {
  160. components: {},
  161. data() {
  162. return {
  163. list: [
  164. {
  165. name: "待支付",
  166. count: 0,
  167. },
  168. {
  169. name: "已支付",
  170. count: 0,
  171. },
  172. {
  173. name: "已取消",
  174. count: 0,
  175. },
  176. {
  177. name: "已退款",
  178. count: 0,
  179. },
  180. ],
  181. current: 0,
  182. order: [],
  183. formData: {
  184. status: "0,1",
  185. pageNum: 1,
  186. pageSize: 10,
  187. },
  188. pageNum1: 0,
  189. pageNum2: 0,
  190. pageNum3: 0,
  191. pageNum4: 0,
  192. };
  193. },
  194. // onPullDownRefresh() {},
  195. onLoad(option) {
  196. this.current = +option.current || 0;
  197. this.getOrderList();
  198. this.getOrderNum();
  199. console.log(this.current);
  200. },
  201. onShow() {
  202. /* if(this.current === 2 && this.$method.isLogin()){
  203. this.$refs.refMy.init();
  204. } */
  205. },
  206. //分享功能
  207. onShareAppMessage(res) {
  208. var self = this;
  209. return {
  210. title: "中正",
  211. path:
  212. `/pages/index/index?inviteCode=` + userInfo == null
  213. ? ""
  214. : userInfo.userAccount,
  215. };
  216. },
  217. onReachBottom() {
  218. this.formData.pageNum++;
  219. this.getFY();
  220. },
  221. methods: {
  222. getOrderNum() {
  223. this.$api
  224. .getorderlists({
  225. status: "0,1",
  226. pageNum: 1,
  227. pageSize: 1,
  228. orderStatus: "0",
  229. })
  230. .then((res) => {
  231. if (res.data.code === 200) {
  232. this.list[0].count = res.data.total;
  233. }
  234. });
  235. this.$api
  236. .getorderlists({
  237. status: "0,1",
  238. pageNum: 1,
  239. pageSize: 1,
  240. orderStatus: "1,2,3,4",
  241. })
  242. .then((res) => {
  243. if (res.data.code === 200) {
  244. this.list[1].count = res.data.total;
  245. }
  246. });
  247. this.$api
  248. .getorderlists({
  249. status: "0,1",
  250. pageNum: 1,
  251. pageSize: 1,
  252. orderStatus: "-1,-2",
  253. })
  254. .then((res) => {
  255. if (res.data.code === 200) {
  256. this.list[2].count = res.data.total;
  257. }
  258. });
  259. },
  260. /**
  261. * 跳转发票申请页面
  262. */
  263. goInvoice() {
  264. uni.navigateTo({
  265. url: `/pages2/invoice/index`,
  266. });
  267. },
  268. refund(orderSn, goodsId) {
  269. uni.showModal({
  270. title: "提示",
  271. content: "确定要退款吗",
  272. success: (res) => {
  273. if (res.confirm) {
  274. let self = this;
  275. this.$api
  276. .refundSmallOrder({ orderSn: orderSn, goodsId: goodsId })
  277. .then((res) => {
  278. if (res.data.code == 200) {
  279. if (res.data.code === 200) {
  280. self.$method.showToast("退款成功");
  281. self.getOrderList();
  282. }
  283. } else {
  284. uni.showToast({
  285. icon: "none",
  286. title: "不可以退款哦",
  287. });
  288. }
  289. });
  290. }
  291. },
  292. });
  293. },
  294. /**
  295. * 跳转课程
  296. */
  297. goCourse(item, orderStatus) {
  298. // if(orderStatus == 1 || orderStatus == 2) {
  299. // console.log(item)
  300. // if(item.goodsType == 1) { //网课
  301. // uni.navigateTo({
  302. // url:'/pages2/wd/course?gid='+item.gradeId+'&id='+item.goodsId
  303. // })
  304. // } else if(item.goodsType == 2) { //题库
  305. // uni.navigateTo({
  306. // url:'/pages2/bank/question_detail?id='+item.goodsId
  307. // })
  308. // }
  309. // }
  310. },
  311. resumeOrder(item) {
  312. let self = this;
  313. uni.login({
  314. provider: "weixin",
  315. success: function (loginRes) {
  316. console.log(loginRes, 69);
  317. self.getOpenid(loginRes.code, item);
  318. },
  319. });
  320. },
  321. getOpenid(code, item) {
  322. let self = this;
  323. this.$api.wxOpenid({ code: code }).then((res) => {
  324. if (res.data.code == 200) {
  325. self.resumeOrderPay(item);
  326. }
  327. });
  328. },
  329. resumeOrderPay(item) {
  330. let data = { orderSn: item.orderSn };
  331. this.$api.resumeSmallOrder(data).then((res) => {
  332. if (res.data.code == 200) {
  333. let data = res.data.data;
  334. uni.requestPayment({
  335. provider: data.provider,
  336. nonceStr: data.nonceStr,
  337. package: data.package,
  338. signType: data.signType,
  339. paySign: data.sign,
  340. timeStamp: String(data.timeStamp),
  341. success: function (res) {
  342. uni.redirectTo({
  343. url: "/pages2/order/confirm_success?sn=" + data.orderSn,
  344. });
  345. console.log("success:" + JSON.stringify(res));
  346. },
  347. fail: function (err) {
  348. console.log("fail:" + JSON.stringify(err));
  349. },
  350. });
  351. } else {
  352. uni.showModal({
  353. title: "提示",
  354. content: res.data.msg,
  355. showCancel: false,
  356. });
  357. }
  358. });
  359. },
  360. openPopup() {},
  361. //删除订单
  362. delOrder(item) {
  363. var self = this;
  364. uni.showModal({
  365. content: "确定要删除该订单吗",
  366. success: function (res) {
  367. if (res.confirm) {
  368. self.$api
  369. .eddOrder({
  370. orderId: item.orderId,
  371. status: -1,
  372. })
  373. .then((res) => {
  374. if (res.data.code === 200) {
  375. self.$method.showToast("订单删除成功");
  376. self.getOrderList();
  377. }
  378. });
  379. }
  380. },
  381. });
  382. },
  383. //取消订单
  384. closeOrder(item) {
  385. var self = this;
  386. uni.showModal({
  387. content: "确定要取消该订单吗",
  388. success: function (res) {
  389. if (res.confirm) {
  390. self.$api
  391. .eddOrder({
  392. orderId: item.orderId,
  393. orderStatus: -1,
  394. })
  395. .then((res) => {
  396. if (res.data.code === 200) {
  397. self.$method.showToast("订单取消成功", "success");
  398. self.getOrderList();
  399. }
  400. });
  401. }
  402. },
  403. });
  404. },
  405. getFY() {
  406. if (this.current === 0) {
  407. this.formData.orderStatus = "0";
  408. if (this.order.length >= this.pageNum1) {
  409. return;
  410. }
  411. }
  412. if (this.current === 1) {
  413. this.formData.orderStatus = "1,2,3,4";
  414. if (this.order.length >= this.pageNum2) {
  415. return;
  416. }
  417. }
  418. if (this.current === 2) {
  419. this.formData.orderStatus = "-1,-2";
  420. if (this.order.length >= this.pageNum3) {
  421. return;
  422. }
  423. }
  424. if (this.current == 3) {
  425. if (this.order.length >= this.pageNum4) {
  426. return;
  427. }
  428. this.formData.orderStatus = "";
  429. this.$api.orderRefundList(this.formData).then((res) => {
  430. if (res.data.code == 200) {
  431. this.order = this.order.concat(res.data.rows);
  432. }
  433. });
  434. return;
  435. }
  436. this.$api.getorderlists(this.formData).then((res) => {
  437. if (res.data.code === 200) {
  438. if (res.data.rows.length) {
  439. this.order = this.order.concat(res.data.rows);
  440. }
  441. }
  442. });
  443. },
  444. //获取订单
  445. getOrderList() {
  446. this.formData.pageNum = 1;
  447. if (this.current === 0) {
  448. this.formData.orderStatus = "0";
  449. }
  450. if (this.current === 1) {
  451. this.formData.orderStatus = "1,2,3,4";
  452. }
  453. if (this.current === 2) {
  454. this.formData.orderStatus = "-1,-2";
  455. }
  456. this.order = [];
  457. this.$api.getorderlists(this.formData).then((res) => {
  458. if (res.data.code === 200) {
  459. if (this.current === 0) {
  460. this.list[0].count = res.data.total;
  461. this.pageNum1 = res.data.total;
  462. }
  463. if (this.current === 1) {
  464. this.list[1].count = res.data.total;
  465. this.pageNum2 = res.data.total;
  466. }
  467. if (this.current === 2) {
  468. this.list[2].count = res.data.total;
  469. this.pageNum3 = res.data.total;
  470. }
  471. this.order = res.data.rows;
  472. }
  473. });
  474. },
  475. orderRefundList() {
  476. this.order = [];
  477. this.formData.pageNum = 1;
  478. this.formData.orderStatus = "";
  479. this.$api.orderRefundList(this.formData).then((res) => {
  480. if (res.data.code == 200) {
  481. this.order = res.data.rows;
  482. }
  483. });
  484. },
  485. change(index) {
  486. if (this.current === index) {
  487. return;
  488. }
  489. this.current = index;
  490. if (this.current == 3) {
  491. //退款订单
  492. this.formData.status = "";
  493. this.orderRefundList();
  494. } else {
  495. //其他订单
  496. this.formData.status = "0,1";
  497. this.getOrderList();
  498. }
  499. uni.pageScrollTo({
  500. scrollTop: 0,
  501. });
  502. },
  503. },
  504. computed: { ...mapGetters(["userInfo"]) },
  505. };
  506. </script>
  507. <style>
  508. page {
  509. background: #eaeef1;
  510. }
  511. </style>
  512. <style scoped lang="scss">
  513. .lisChild {
  514. border-radius: 16rpx;
  515. margin-bottom: 16rpx;
  516. background: #fff;
  517. .header {
  518. display: flex;
  519. justify-content: space-between;
  520. align-items: center;
  521. height: 80rpx;
  522. padding: 0 15rpx;
  523. color: #666666;
  524. font-size: 24rpx;
  525. }
  526. .body {
  527. padding: 16rpx;
  528. &__content {
  529. display: flex;
  530. justify-content: space-between;
  531. .goods-img {
  532. height: 156rpx;
  533. width: 278rpx;
  534. border-radius: 16rpx;
  535. flex-shrink: 0;
  536. }
  537. .goods-text {
  538. margin-left: 20rpx;
  539. flex: 1;
  540. display: flex;
  541. flex-direction: column;
  542. .goods-name {
  543. color: #333333;
  544. font-size: 30rpx;
  545. font-weight: bold;
  546. flex: 1;
  547. }
  548. .goods-price {
  549. font-size: 30rpx;
  550. font-family: PingFang SC;
  551. font-weight: bold;
  552. color: #ff2d55;
  553. display: flex;
  554. flex-direction: row-reverse;
  555. }
  556. }
  557. }
  558. .btn2 {
  559. width: 144rpx;
  560. height: 46rpx;
  561. background: #ffffff;
  562. border: 2rpx solid #007aff;
  563. border-radius: 16rpx;
  564. text-align: center;
  565. line-height: 48rpx;
  566. color: #007aff;
  567. margin: 0 8rpx;
  568. }
  569. }
  570. .footer {
  571. padding: 0 24rpx;
  572. height: 80rpx;
  573. display: flex;
  574. justify-content: space-between;
  575. align-items: center;
  576. .btn2 {
  577. width: 144rpx;
  578. height: 46rpx;
  579. background: #ffffff;
  580. border: 2rpx solid #007aff;
  581. border-radius: 16rpx;
  582. text-align: center;
  583. line-height: 48rpx;
  584. color: #007aff;
  585. margin: 0 8rpx;
  586. }
  587. .btn1 {
  588. width: 144rpx;
  589. height: 48rpx;
  590. background: #ffffff;
  591. border: 2rpx solid #999999;
  592. border-radius: 16rpx;
  593. text-align: center;
  594. line-height: 48rpx;
  595. color: #999999;
  596. margin: 0 8rpx;
  597. }
  598. }
  599. }
  600. .lisChild:last-child {
  601. margin-bottom: 34rpx;
  602. }
  603. .noData {
  604. text-align: center;
  605. font-size: 32rpx;
  606. font-family: PingFang SC;
  607. font-weight: 500;
  608. color: #999999;
  609. margin: 160rpx 0;
  610. }
  611. .apply-invoice {
  612. z-index: 100;
  613. position: fixed;
  614. left: 0;
  615. right: 0;
  616. bottom: 40rpx;
  617. margin: 0 auto;
  618. width: 526rpx;
  619. height: 80rpx;
  620. text-align: center;
  621. line-height: 80rpx;
  622. color: #fff;
  623. background: #007aff;
  624. box-shadow: 0rpx 8rpx 7rpx 1rpx rgba(0, 122, 255, 0.1);
  625. border-radius: 40rpx;
  626. }
  627. .bottomBox {
  628. position: fixed;
  629. bottom: 0;
  630. width: 100%;
  631. left: 0;
  632. height: 98rpx;
  633. background-color: #ffffff;
  634. display: flex;
  635. justify-content: space-between;
  636. align-items: center;
  637. padding: 0 30rpx;
  638. }
  639. </style>