index.vue 8.6 KB

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