index.vue 13 KB

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