index.vue 9.7 KB

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