order.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="我的订单"
  5. :placeholder="true"
  6. :autoBack="false"
  7. @leftClick="leftClick"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. <view class="tabs-wrap">
  12. <u-tabs
  13. :list="tabsList"
  14. lineColor="#EE0D0D"
  15. :current="tabsCurrent"
  16. :activeStyle="{color:'#EE0D0D','font-weight': '600','font-size':'30rpx'}"
  17. :inactiveStyle="{color:'#7F7F7F'}"
  18. itemStyle="width:20%;box-sizing:border-box;padding:24rpx"
  19. @click="tabsClick"></u-tabs>
  20. </view>
  21. <view class="page-wrap">
  22. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  23. <view class="order">
  24. <view v-for="(item,index) in orderListWithClass" class="order-item"
  25. :class="item.class"
  26. @click="goOrderDetails(item.id)" :key="item.id">
  27. <view class="top u-flex u-row-between">
  28. <text>遵义《伟大转折》演艺中心</text>
  29. <text>待支付</text>
  30. </view>
  31. <view class="info u-flex u-col-top">
  32. <image class="img" :src="item.showImg||staticUrl+'/img/newsdetails-banner.png'"></image>
  33. <view class="text">
  34. <view class="name">《伟大转折》-【成人票】</view>
  35. <view class="time">2023-11–03 14:00-16:00</view>
  36. <view class="position">5排6座</view>
  37. <view class="statistics">
  38. <text>共1张</text>
  39. <text class="label">合计:</text>
  40. <text class="price">¥120.00</text>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="btn-wrap u-flex u-row-right">
  45. <view
  46. class="btn"
  47. :class="btn.class"
  48. @click.stop="clickEven(btn.fun,item)"
  49. v-for="(btn,index) in statusBtn[item.status]" :key="index">
  50. {{btn.name}}
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </mescroll-body>
  56. </view>
  57. <u-toast ref="uToast"></u-toast>
  58. <tabbar :tabbarIndexProps="1" />
  59. </view>
  60. </template>
  61. <script>
  62. import tabbar from "../components/tabbar.vue";
  63. // 引入mescroll-mixins.js
  64. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  65. export default {
  66. mixins: [MescrollMixin], // 使用mixin
  67. components:{
  68. tabbar
  69. },
  70. data() {
  71. return {
  72. staticUrl:this.$commonConfig.staticUrl,
  73. goodsKey:1,
  74. hasfetch:false,
  75. tabsCurrent:1,
  76. tabsList:[
  77. {name:'全部',status:'',},
  78. {name:'待支付',status:'0',badge:{isDot:false,value:null}},
  79. {name:'待使用',status:'1',badge:{isDot:false,value:null}},
  80. {name:'已完成',status:'2',badge:{isDot:false,value:null}},
  81. {name:'售后',status:'3',badge:{isDot:false,value:null}}
  82. ],
  83. status:'',
  84. dataList:[{id:1,status:2}],
  85. statusBtn:{
  86. 0:[{name:'取消订单',fun:'cancelOrder',class:''},{name:'去支付',fun:'pay',class:'red'}],
  87. 1:[{name:'申请退款',fun:'refund',class:''}],
  88. 2:[{name:'取消订单',fun:'cancelOrder',class:''},{name:'去支付',fun:'pay',class:'red solid'}],
  89. 3:[{name:'查看物流',fun:'logistics',class:''}],
  90. //,{name:'评价',fun:'evaluate',class:'green'}
  91. // 4:[{name:'查看物流',fun:'logistics',class:''},{name:'评价',fun:'evaluate',class:'green'}],
  92. 5:[{name:'查看退款',fun:'viewRefund',class:'green'}],
  93. 6:[{name:'查看物流',fun:'logistics',class:''}],
  94. // ,{name:'查看评价',fun:'viewEvaluate',class:'green'}
  95. 7:[{name:'查看退款',fun:'viewRefund',class:'green'}]
  96. },
  97. orderBadge:{
  98. noPayNum:0,
  99. deliverNum:0,
  100. collectNum:0,
  101. commentNum:0,
  102. refundNum:0,
  103. },
  104. }
  105. },
  106. computed: {
  107. orderListWithClass() {
  108. return this.dataList.map(order => {
  109. // let spliceData = order.detailList.splice(0,2);
  110. // let moreData = order.detailList.splice(2,order.detailList.length);
  111. // let moreData = order.detailList.slice(2);
  112. // if(order.detailList.length>2){
  113. // moreData = order.detailList;
  114. // }
  115. return {
  116. ...order,
  117. // spliceData:spliceData,
  118. // moreData:moreData,
  119. // showMore:false,
  120. class: {
  121. 0: 'status-0',
  122. 1: 'status-1',
  123. 2: 'status-2',
  124. 3: 'status-3',
  125. 4: 'status-4',
  126. 5: 'status-5',
  127. 6: 'status-6',
  128. 7: 'status-7',
  129. 8: 'status-8'
  130. }[order.status] || ''
  131. }
  132. })
  133. }
  134. },
  135. onLoad(page) {
  136. // console.log('page',page);
  137. const status = page.status;
  138. const index = this.tabsList.findIndex(item => item.status === status);
  139. this.tabsCurrent = index>=0?index:0;
  140. },
  141. onShow() {
  142. setTimeout(()=>{
  143. this.hasfetch&&this.reloadList()
  144. },500);
  145. this.statisticsOrder();
  146. },
  147. methods: {
  148. leftClick(){
  149. uni.reLaunch({url: '/center/center'});
  150. },
  151. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  152. downCallback(){
  153. this.mescroll.resetUpScroll();
  154. },
  155. /*上拉加载的回调*/
  156. upCallback(page) {
  157. this.statisticsOrder();
  158. // 此处可以继续请求其他接口
  159. // if(page.num == 1){
  160. // // 请求其他接口...
  161. // }
  162. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  163. // if(!this.hasTypeId){
  164. // this.shopNewsType();
  165. // return // 此处return,先获取xx
  166. // }
  167. let pageNum = page.num; // 页码, 默认从1开始
  168. let pageSize = page.size; // 页长, 默认每页10条
  169. let params = {
  170. pageNum : page.num,
  171. pageSize : page.size,
  172. status : this.tabsList[this.tabsCurrent]?.status||'',
  173. // status : this.tabsList[this.tabsCurrent].status,
  174. }
  175. // console.log('this.params',params);
  176. this.$u.api.orderList(params).then(data => {
  177. this.hasfetch = true;
  178. console.log('data',JSON.parse(JSON.stringify(data)));
  179. // 接口返回的当前页数据列表 (数组)
  180. let curPageData = data.data.rows;
  181. // console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  182. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  183. let curPageLen = curPageData.length;
  184. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  185. // let totalPage = data.data.data.totalPage;
  186. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  187. let totalSize = data.data.total;
  188. // 接口返回的是否有下一页 (true/false)
  189. // let hasNext = data.xxx;
  190. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  191. //设置列表数据
  192. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  193. this.dataList = this.dataList.concat(curPageData); //追加新数据
  194. // 请求成功,隐藏加载状态
  195. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  196. // this.mescroll.endByPage(curPageLen, totalPage);
  197. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  198. this.mescroll.endBySize(curPageLen, totalSize);
  199. }).catch(err => {
  200. this.mescroll.endErr()
  201. console.log(err)
  202. });
  203. },
  204. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  205. reloadList() {
  206. this.mescroll.resetUpScroll();
  207. },
  208. tabsClick(item){
  209. // this.status = item.status;
  210. this.tabsCurrent = item.index;
  211. this.reloadList()
  212. // console.log('item',item);
  213. },
  214. goOrderDetails(id){
  215. uni.$u.route('/center/orderdetails', {
  216. id: id
  217. });
  218. },
  219. toggleMore(item,index){
  220. // console.log('toggleMore',item);
  221. this.orderListWithClass[index].showMore = !this.orderListWithClass[index].showMore
  222. this.goodsKey++;
  223. },
  224. clickEven(fun,item){
  225. // console.log('fun',fun);
  226. let funObj = {
  227. pay: this.pay,
  228. logistics:this.logistics,
  229. evaluate:this.evaluate,
  230. refund:this.refund,
  231. cancelOrder:this.cancelOrder,
  232. viewRefund:this.viewRefund,
  233. confirmReceipt:this.confirmReceipt,
  234. viewEvaluate:this.viewEvaluate
  235. };
  236. // console.log('funObj[fun]',funObj[fun]);
  237. if (fun in funObj) {
  238. funObj[fun](item);
  239. }
  240. },
  241. pay(item){
  242. console.log('pay',item);
  243. uni.$u.route('/shopping/pay', {
  244. orderId: item.id,
  245. // openid: that.vuex_wechatOpenid,
  246. payAmount:item.orderPrice
  247. });
  248. },
  249. logistics(item){
  250. // console.log('logistics',item);
  251. uni.$u.route('/shopping/distribution', {
  252. orderId: item.id
  253. });
  254. },
  255. evaluate(item){
  256. // console.log('logistics',item);
  257. uni.$u.route('/shopping/evaluate', {
  258. id: item.id
  259. });
  260. },
  261. comment(orderId,orderDetailId,goodsId){
  262. uni.$u.route('/shopping/addcomment', {
  263. orderId,
  264. orderDetailId,
  265. goodsId
  266. });
  267. },
  268. viewComment(orderDetailId,goodsId,goods){
  269. uni.$u.route('/shopping/viewcomment', {
  270. orderDetailId,
  271. goodsId,
  272. goods:JSON.stringify(goods)
  273. });
  274. },
  275. refund(item){
  276. // console.log('logistics',item);
  277. uni.$u.route('/shopping/refund', {
  278. id: item.id
  279. });
  280. },
  281. cancelOrder(item){
  282. let that = this;
  283. uni.showModal({
  284. title: '提示',
  285. content: '确认取消吗!',
  286. success: res => {
  287. if (res.confirm) {
  288. this.$u.api.cancelOrder({orderId:item.id}).then(res=>{
  289. this.$refs.uToast.show({
  290. message:res.msg,
  291. complete() {
  292. that.reloadList();
  293. }
  294. });
  295. // uni.$u.toast(res.msg);
  296. console.log('res',res.data);
  297. }).catch(err=>{
  298. console.log('cancelOrder',err);
  299. })
  300. }
  301. }
  302. });
  303. // console.log('logistics',item);
  304. },
  305. viewRefund(item){
  306. uni.$u.route('/shopping/viewRefund', {
  307. orderId: item.id
  308. });
  309. },
  310. confirmReceipt(item){
  311. let that = this;
  312. uni.showModal({
  313. title: '提示',
  314. content: '确认收货吗!',
  315. success: res => {
  316. if (res.confirm) {
  317. this.$u.api.confirmReceipt({orderId:item.id}).then(res=>{
  318. uni.showToast({
  319. title:res.msg,
  320. duration:2000,
  321. complete() {
  322. that.reloadList();
  323. }
  324. });
  325. console.log('res',res.data);
  326. }).catch(err=>{
  327. console.log('confirmReceipt',err);
  328. })
  329. }
  330. }
  331. })
  332. },
  333. viewEvaluate(item){
  334. uni.$u.route('/shopping/orderdetails', {
  335. id: item.id
  336. });
  337. },
  338. statisticsOrder(){
  339. this.$u.api.statisticsOrder().then(res=>{
  340. let data = res.data || {};
  341. this.orderBadge = Object.assign(this.orderBadge,data);
  342. let {noPayNum,deliverNum,collectNum,commentNum,refundNum} = res.data;
  343. let noPayNumindex = this.tabsList.findIndex(item => item.status == 0);
  344. this.tabsList[1].badge.isDot = false;
  345. this.tabsList[1].badge.value = noPayNum;
  346. this.tabsList[2].badge.isDot = false;
  347. this.tabsList[2].badge.value = deliverNum;
  348. this.tabsList[3].badge.isDot = false;
  349. this.tabsList[3].badge.value = collectNum;
  350. this.tabsList[4].badge.isDot = false;
  351. this.tabsList[4].badge.value = commentNum;
  352. this.tabsList[5].badge.isDot = false;
  353. this.tabsList[5].badge.value = refundNum;
  354. // console.log('statisticsOrder',res.data);
  355. // console.log('this.orderBadge',this.orderBadge);
  356. }).catch(err=>{
  357. console.log('memberInfo',err.data);
  358. })
  359. }
  360. }
  361. }
  362. </script>
  363. <style>
  364. page{
  365. background-color: #F5F5F5;
  366. }
  367. </style>
  368. <style lang="scss" scoped>
  369. .tabs-wrap{
  370. background-color: #fff;
  371. margin-bottom: 10rpx;
  372. }
  373. .list-item{
  374. overflow: hidden;
  375. width: 48%;
  376. margin-bottom: 30rpx;
  377. background-color: #fff;
  378. .image-wrap{
  379. margin-bottom: 20rpx;
  380. }
  381. }
  382. .order-item{
  383. margin-bottom: 20rpx;
  384. background: #FFFFFF;
  385. box-shadow: 0rpx 2rpx 12rpx 0rpx rgba(221,221,221,0.5);
  386. border-radius: 20rpx;
  387. padding: 32rpx;
  388. .top{
  389. font-size: 24rpx;
  390. font-weight: 400;
  391. color: #7F7F7F;
  392. line-height: 36rpx;
  393. margin-bottom: 36rpx;
  394. }
  395. .info{
  396. margin-bottom: 30rpx;
  397. .img{
  398. width: 180rpx;
  399. height: 160rpx;
  400. }
  401. .text{
  402. font-size: 24rpx;
  403. font-weight: 400;
  404. color: #7F7F7F;
  405. padding-left: 26rpx;
  406. flex: 1;
  407. .name{
  408. font-size: 28rpx;
  409. font-weight: bold;
  410. color: #363636;
  411. margin-bottom: 20rpx;
  412. }
  413. .time{
  414. margin-bottom: 20rpx;
  415. }
  416. .position{
  417. margin-bottom: 20rpx;
  418. }
  419. .statistics{
  420. text-align: right;
  421. }
  422. .label{
  423. font-size: 24rpx;
  424. font-weight: 400;
  425. color: #363636;
  426. margin-left: 10rpx;
  427. }
  428. .price{
  429. font-size: 32rpx;
  430. font-weight: bold;
  431. color: #ED0000;
  432. }
  433. }
  434. }
  435. .btn-wrap{
  436. }
  437. .btn{
  438. padding: 12rpx 40rpx;
  439. border: 1px solid #E5E5E5;
  440. color: #7F7F7F;
  441. text-align: center;
  442. border-radius: 8rpx;
  443. font-size: 24rpx;
  444. &.red{border-color: #ED0000;color: #ED0000;}
  445. &.red.solid{border-color: #ED0000;background-color:#ED0000;color: #fff;}
  446. &.green{color: #00A447;border-color: #00A447;}
  447. &:not(:first-child){
  448. margin-left: 20rpx;
  449. }
  450. }
  451. &.status-0{.status{color:#FF3C3F;}}
  452. &.status-1{.status{color:#FF3C3F;}}
  453. &.status-2{.status{color:#0099EB;}}
  454. &.status-3{.status{color:#00A447;}}
  455. &.status-4{.status{color:#FF3C3F;}}
  456. &.status-5{.status{color:#FF3C3F;}}
  457. &.status-6{.status{color:#FF3C3F;}}
  458. &.status-7{.status{color:#FFB100;}}
  459. }
  460. </style>