order.vue 13 KB

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