order.vue 15 KB

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