order.vue 15 KB

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