order.vue 15 KB

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