order.vue 15 KB

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