index.vue 16 KB

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