index.vue 12 KB

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