order.vue 13 KB

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