order.vue 12 KB

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