index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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 130rpx">
  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 v-if="item.orderFrom !== 6" 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 v-if="items.periodStatus !== null">{{
  90. [
  91. "复审不通过",
  92. "初审不通过",
  93. "待审核",
  94. "初审通过",
  95. "复审通过待退款",
  96. "已退款",
  97. ][items.periodStatus + 2]
  98. }}</view>
  99. </view>
  100. </view>
  101. </view>
  102. <u-line color="#D6D6DB" />
  103. <view class="footer" v-if="current == 3">
  104. <view>
  105. <text style="color: #999; font-size: 24rpx; margin-right: 8rpx"
  106. >退款金额</text
  107. >
  108. <text
  109. style="color: #ff2d55; font-size: 30rpx; font-weight: bold"
  110. >¥{{ item.refundFee }}</text
  111. >
  112. </view>
  113. </view>
  114. <view class="footer" v-else>
  115. <view>
  116. <text style="color: #999; font-size: 24rpx; margin-right: 8rpx"
  117. >共{{ item.orderGoodsList.length }}项</text
  118. >
  119. <!-- 业务系统下单的需要隐藏价格 -->
  120. <!-- 订单来源:1业务员普通单,2祥粤云学堂小程序,3祥粤云学堂网站,4祥粤e管证小程序,5业务员录单,6业务系统下单 -->
  121. <text v-if="item.orderFrom !== 6">
  122. <text style="color: #333; font-size: 30rpx; font-weight: bold"
  123. >合计</text
  124. >
  125. <text
  126. style="color: #ff2d55; font-size: 30rpx; font-weight: bold"
  127. >¥{{ item.payPrice }}</text
  128. >
  129. </text>
  130. </view>
  131. <view style="display: flex; align-items: center">
  132. <view
  133. class="btn2"
  134. v-if="
  135. item.orderStatus === 0 &&
  136. (item.orderFrom === 2 || item.orderFrom === 3)
  137. "
  138. @click="resumeOrder(item)"
  139. >继续支付</view
  140. >
  141. <!-- <view class="btn2" v-if="item.orderStatus === -1 || item.orderStatus === -2" @click="againBuy(item)">重新购买</view> -->
  142. <view
  143. class="btn1"
  144. v-if="
  145. (item.orderStatus === -1 || item.orderStatus === -2) &&
  146. (item.orderFrom === 2 || item.orderFrom === 3)
  147. "
  148. @click="delOrder(item)"
  149. >删除订单</view
  150. >
  151. <view
  152. class="btn1"
  153. @click="closeOrder(item)"
  154. v-if="
  155. item.orderStatus === 0 &&
  156. (item.orderFrom === 2 || item.orderFrom === 3)
  157. "
  158. >取消订单</view
  159. >
  160. </view>
  161. </view>
  162. </view>
  163. </view>
  164. </template>
  165. <template v-if="current == 1 && order.length">
  166. <view class="apply_btn">
  167. <view class="apply-invoice" @click="goInvoice">发票申请</view>
  168. </view>
  169. </template>
  170. </view>
  171. </view>
  172. </template>
  173. <script>
  174. import { mapGetters } from "vuex";
  175. export default {
  176. components: {},
  177. data() {
  178. return {
  179. list: [
  180. {
  181. name: "待支付",
  182. count: 0,
  183. },
  184. {
  185. name: "已支付",
  186. count: 0,
  187. },
  188. {
  189. name: "已取消",
  190. count: 0,
  191. },
  192. {
  193. name: "已退款",
  194. count: 0,
  195. },
  196. ],
  197. current: 0,
  198. order: [],
  199. formData: {
  200. status: "0,1",
  201. pageNum: 1,
  202. pageSize: 10,
  203. },
  204. pageNum1: 0,
  205. pageNum2: 0,
  206. pageNum3: 0,
  207. pageNum4: 0,
  208. };
  209. },
  210. // onPullDownRefresh() {},
  211. onLoad(option) {
  212. this.current = +option.current || 0;
  213. this.getOrderList();
  214. this.getOrderNum();
  215. console.log(this.current);
  216. },
  217. onShow() {
  218. /* if(this.current === 2 && this.$method.isLogin()){
  219. this.$refs.refMy.init();
  220. } */
  221. },
  222. //分享功能
  223. onShareAppMessage(res) {
  224. var self = this;
  225. return {
  226. title: "中正",
  227. path:
  228. `/pages/index/index?inviteCode=` + userInfo == null
  229. ? ""
  230. : userInfo.userAccount,
  231. };
  232. },
  233. onReachBottom() {
  234. this.formData.pageNum++;
  235. this.getFY();
  236. },
  237. methods: {
  238. getOrderNum() {
  239. this.$api
  240. .getorderlists({
  241. status: "0,1",
  242. pageNum: 1,
  243. pageSize: 1,
  244. orderStatus: "0",
  245. })
  246. .then((res) => {
  247. if (res.data.code === 200) {
  248. this.list[0].count = res.data.total;
  249. }
  250. });
  251. this.$api
  252. .getorderlists({
  253. status: "0,1",
  254. pageNum: 1,
  255. pageSize: 1,
  256. orderStatus: "1,2,3,4",
  257. })
  258. .then((res) => {
  259. if (res.data.code === 200) {
  260. this.list[1].count = res.data.total;
  261. }
  262. });
  263. this.$api
  264. .getorderlists({
  265. status: "0,1",
  266. pageNum: 1,
  267. pageSize: 1,
  268. orderStatus: "-1,-2",
  269. })
  270. .then((res) => {
  271. if (res.data.code === 200) {
  272. this.list[2].count = res.data.total;
  273. }
  274. });
  275. },
  276. /**
  277. * 跳转发票申请页面
  278. */
  279. goInvoice() {
  280. uni.navigateTo({
  281. url: `/pages2/invoice/index`,
  282. });
  283. },
  284. refund(orderSn, goodsId) {
  285. uni.showModal({
  286. title: "提示",
  287. content: "确定要退款吗",
  288. success: (res) => {
  289. if (res.confirm) {
  290. let self = this;
  291. this.$api
  292. .refundSmallOrder({ orderSn: orderSn, goodsId: goodsId })
  293. .then((res) => {
  294. if (res.data.code == 200) {
  295. if (res.data.code === 200) {
  296. self.$method.showToast("退款成功");
  297. self.getOrderList();
  298. }
  299. } else {
  300. uni.showToast({
  301. icon: "none",
  302. title: res.data.msg,
  303. });
  304. }
  305. });
  306. }
  307. },
  308. });
  309. },
  310. /**
  311. * 跳转课程
  312. */
  313. goCourse(item, orderStatus) {
  314. // if(orderStatus == 1 || orderStatus == 2) {
  315. // console.log(item)
  316. // if(item.goodsType == 1) { //网课
  317. // uni.navigateTo({
  318. // url:'/pages2/wd/course?gid='+item.gradeId+'&id='+item.goodsId
  319. // })
  320. // } else if(item.goodsType == 2) { //题库
  321. // uni.navigateTo({
  322. // url:'/pages2/bank/question_detail?id='+item.goodsId
  323. // })
  324. // }
  325. // }
  326. },
  327. resumeOrder(item) {
  328. let self = this;
  329. // #ifdef MP-WEIXIN
  330. uni.login({
  331. provider: "weixin",
  332. success: function (loginRes) {
  333. console.log(loginRes, 69);
  334. self.getOpenid(loginRes.code, item);
  335. },
  336. });
  337. // #endif
  338. // #ifdef H5
  339. // 在首页已经请求过接口/gzh_login 提交code了
  340. this.resumeOrderPay(item);
  341. // #endif
  342. },
  343. getOpenid(code, item) {
  344. let self = this;
  345. this.$api.wxOpenid({ code: code }).then((res) => {
  346. if (res.data.code == 200) {
  347. self.resumeOrderPay(item);
  348. }
  349. });
  350. },
  351. resumeOrderPay(item) {
  352. let data = { orderSn: item.orderSn };
  353. // #ifdef MP-WEIXIN
  354. this.$api.resumeSmallOrder(data).then((res) => {
  355. if (res.data.code == 200) {
  356. let data = res.data.data;
  357. uni.requestPayment({
  358. provider: data.provider,
  359. nonceStr: data.nonceStr,
  360. package: data.package,
  361. signType: data.signType,
  362. paySign: data.sign,
  363. timeStamp: String(data.timeStamp),
  364. success: function (res) {
  365. uni.redirectTo({
  366. url: "/pages2/order/confirm_success?sn=" + data.orderSn,
  367. });
  368. console.log("success:" + JSON.stringify(res));
  369. },
  370. fail: function (err) {
  371. console.log("fail:" + JSON.stringify(err));
  372. },
  373. });
  374. } else {
  375. uni.showModal({
  376. title: "提示",
  377. content: res.data.msg,
  378. showCancel: false,
  379. });
  380. }
  381. });
  382. // #endif
  383. // #ifdef H5
  384. data["url"] = location.href;
  385. this.$api.resumePlaceGzhOrder(data).then((res) => {
  386. console.log(res, "继续支付res");
  387. if (res.data.code == 200) {
  388. this.h5_wxpay(res.data.data);
  389. } else {
  390. uni.showModal({
  391. title: "提示",
  392. content: res.data.msg,
  393. showCancel: false,
  394. });
  395. }
  396. });
  397. // #endif
  398. },
  399. h5_wxpay(data) {
  400. console.log("调起支付状态1", data);
  401. let self = this;
  402. function onBridgeReady() {
  403. // 加载框
  404. WeixinJSBridge.invoke(
  405. "getBrandWCPayRequest",
  406. {
  407. appId: data.appId, // 公众号名称,由商户传入
  408. timeStamp: data.timeStamp, // 时间戳,自1970年以来的秒数
  409. nonceStr: data.nonceStr, // 随机串
  410. package: data.package,
  411. signType: data.signType, // 微信签名方式:
  412. paySign: data.paySign, // 微信签名
  413. },
  414. function (res) {
  415. // 判断支付状态
  416. console.log("支付状态", res, "this:", this, self);
  417. if (res.err_msg === "get_brand_wcpay_request:ok") {
  418. self.$u.toast("支付成功");
  419. uni.redirectTo({
  420. url: "/pages2/order/confirm_success?sn=" + data.orderSn,
  421. });
  422. } else if (res.err_msg === "get_brand_wcpay_request:cancel") {
  423. self.$u.toast("取消支付");
  424. } else {
  425. self.$u.toast("支付失败");
  426. }
  427. }
  428. );
  429. }
  430. if (typeof WeixinJSBridge === "undefined") {
  431. if (document.addEventListener) {
  432. document.addEventListener(
  433. "WeixinJSBridgeReady",
  434. onBridgeReady,
  435. false
  436. );
  437. } else if (document.attachEvent) {
  438. document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
  439. document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
  440. }
  441. } else {
  442. onBridgeReady();
  443. }
  444. },
  445. openPopup() {},
  446. //删除订单
  447. delOrder(item) {
  448. var self = this;
  449. uni.showModal({
  450. content: "确定要删除该订单吗",
  451. success: function (res) {
  452. if (res.confirm) {
  453. self.$api
  454. .eddOrder({
  455. orderId: item.orderId,
  456. status: -1,
  457. })
  458. .then((res) => {
  459. if (res.data.code === 200) {
  460. self.$method.showToast("订单删除成功");
  461. self.getOrderList();
  462. }
  463. });
  464. }
  465. },
  466. });
  467. },
  468. //取消订单
  469. closeOrder(item) {
  470. var self = this;
  471. uni.showModal({
  472. content: "确定要取消该订单吗",
  473. success: function (res) {
  474. if (res.confirm) {
  475. self.$api
  476. .eddOrder({
  477. orderId: item.orderId,
  478. orderStatus: -1,
  479. })
  480. .then((res) => {
  481. if (res.data.code === 200) {
  482. self.$method.showToast("订单取消成功", "success");
  483. self.getOrderList();
  484. }
  485. });
  486. }
  487. },
  488. });
  489. },
  490. getFY() {
  491. if (this.current === 0) {
  492. this.formData.orderStatus = "0";
  493. if (this.order.length >= this.pageNum1) {
  494. return;
  495. }
  496. }
  497. if (this.current === 1) {
  498. this.formData.orderStatus = "1,2,3,4";
  499. if (this.order.length >= this.pageNum2) {
  500. return;
  501. }
  502. }
  503. if (this.current === 2) {
  504. this.formData.orderStatus = "-1,-2";
  505. if (this.order.length >= this.pageNum3) {
  506. return;
  507. }
  508. }
  509. if (this.current == 3) {
  510. if (this.order.length >= this.pageNum4) {
  511. return;
  512. }
  513. this.formData.orderStatus = "";
  514. this.$api.orderRefundList(this.formData).then((res) => {
  515. if (res.data.code == 200) {
  516. this.order = this.order.concat(res.data.rows);
  517. }
  518. });
  519. return;
  520. }
  521. this.$api.getorderlists(this.formData).then((res) => {
  522. if (res.data.code === 200) {
  523. if (res.data.rows.length) {
  524. this.order = this.order.concat(res.data.rows);
  525. }
  526. }
  527. });
  528. },
  529. //获取订单
  530. getOrderList() {
  531. this.formData.pageNum = 1;
  532. if (this.current === 0) {
  533. this.formData.orderStatus = "0";
  534. }
  535. if (this.current === 1) {
  536. this.formData.orderStatus = "1,2,3,4";
  537. }
  538. if (this.current === 2) {
  539. this.formData.orderStatus = "-1,-2";
  540. }
  541. this.order = [];
  542. this.$api.getorderlists(this.formData).then((res) => {
  543. if (res.data.code === 200) {
  544. if (this.current === 0) {
  545. this.list[0].count = res.data.total;
  546. this.pageNum1 = res.data.total;
  547. }
  548. if (this.current === 1) {
  549. this.list[1].count = res.data.total;
  550. this.pageNum2 = res.data.total;
  551. }
  552. if (this.current === 2) {
  553. this.list[2].count = res.data.total;
  554. this.pageNum3 = res.data.total;
  555. }
  556. this.order = res.data.rows;
  557. console.log("订单列表this.order", this.order);
  558. }
  559. });
  560. },
  561. orderRefundList() {
  562. this.order = [];
  563. this.formData.pageNum = 1;
  564. this.formData.orderStatus = "";
  565. this.$api.orderRefundList(this.formData).then((res) => {
  566. if (res.data.code == 200) {
  567. this.order = res.data.rows;
  568. }
  569. });
  570. },
  571. change(index) {
  572. if (this.current === index) {
  573. return;
  574. }
  575. this.current = index;
  576. console.log("this.current", this.current);
  577. if (this.current == 3) {
  578. //退款订单
  579. this.formData.status = "";
  580. this.orderRefundList();
  581. } else {
  582. //其他订单
  583. this.formData.status = "0,1";
  584. this.getOrderList();
  585. }
  586. uni.pageScrollTo({
  587. scrollTop: 0,
  588. });
  589. },
  590. },
  591. computed: { ...mapGetters(["userInfo"]) },
  592. };
  593. </script>
  594. <style>
  595. page {
  596. background: #eaeef1;
  597. }
  598. </style>
  599. <style scoped lang="scss">
  600. .lisChild {
  601. border-radius: 16rpx;
  602. margin-bottom: 16rpx;
  603. background: #fff;
  604. .header {
  605. display: flex;
  606. justify-content: space-between;
  607. align-items: center;
  608. height: 80rpx;
  609. padding: 0 15rpx;
  610. color: #666666;
  611. font-size: 24rpx;
  612. }
  613. .body {
  614. padding: 16rpx;
  615. &__content {
  616. display: flex;
  617. justify-content: space-between;
  618. .goods-img {
  619. height: 156rpx;
  620. width: 278rpx;
  621. border-radius: 16rpx;
  622. flex-shrink: 0;
  623. }
  624. .goods-text {
  625. margin-left: 20rpx;
  626. flex: 1;
  627. display: flex;
  628. flex-direction: column;
  629. .goods-name {
  630. color: #333333;
  631. font-size: 30rpx;
  632. font-weight: bold;
  633. flex: 1;
  634. }
  635. .goods-price {
  636. font-size: 30rpx;
  637. font-family: PingFang SC;
  638. font-weight: bold;
  639. color: #ff2d55;
  640. display: flex;
  641. flex-direction: row-reverse;
  642. }
  643. }
  644. }
  645. .btn2 {
  646. width: 144rpx;
  647. height: 46rpx;
  648. background: #ffffff;
  649. border: 2rpx solid #007aff;
  650. border-radius: 16rpx;
  651. text-align: center;
  652. line-height: 48rpx;
  653. color: #007aff;
  654. margin: 0 8rpx;
  655. }
  656. }
  657. .footer {
  658. padding: 0 24rpx;
  659. height: 80rpx;
  660. display: flex;
  661. justify-content: space-between;
  662. align-items: center;
  663. .btn2 {
  664. width: 144rpx;
  665. height: 46rpx;
  666. background: #ffffff;
  667. border: 2rpx solid #007aff;
  668. border-radius: 16rpx;
  669. text-align: center;
  670. line-height: 48rpx;
  671. color: #007aff;
  672. margin: 0 8rpx;
  673. }
  674. .btn1 {
  675. width: 144rpx;
  676. height: 48rpx;
  677. background: #ffffff;
  678. border: 2rpx solid #999999;
  679. border-radius: 16rpx;
  680. text-align: center;
  681. line-height: 48rpx;
  682. color: #999999;
  683. margin: 0 8rpx;
  684. }
  685. }
  686. }
  687. .lisChild:last-child {
  688. margin-bottom: 34rpx;
  689. }
  690. .noData {
  691. text-align: center;
  692. font-size: 32rpx;
  693. font-family: PingFang SC;
  694. font-weight: 500;
  695. color: #999999;
  696. margin: 160rpx 0;
  697. }
  698. .apply_btn {
  699. width: 100%;
  700. height: 124rpx;
  701. background: #ffffff;
  702. box-shadow: 0rpx -2rpx 6rpx 0rpx rgba(0, 0, 0, 0.1);
  703. z-index: 100;
  704. position: fixed;
  705. left: 0;
  706. right: 0;
  707. bottom: 0rpx;
  708. }
  709. .apply-invoice {
  710. margin: 0 auto;
  711. width: 686rpx;
  712. height: 84rpx;
  713. line-height: 84rpx;
  714. text-align: center;
  715. font-size: 32rpx;
  716. color: #fff;
  717. background: #0080ff;
  718. margin-top: 20rpx;
  719. border-radius: 120rpx;
  720. }
  721. .bottomBox {
  722. position: fixed;
  723. bottom: 0;
  724. width: 100%;
  725. left: 0;
  726. height: 98rpx;
  727. background-color: #ffffff;
  728. display: flex;
  729. justify-content: space-between;
  730. align-items: center;
  731. padding: 0 30rpx;
  732. }
  733. </style>