index.vue 13 KB

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