order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="我的订单"
  5. :autoBack="true"
  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.$u.route('/center/center', {
  140. // type: 'reLaunch'
  141. // });
  142. },
  143. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  144. downCallback(){
  145. this.mescroll.resetUpScroll();
  146. },
  147. /*上拉加载的回调*/
  148. upCallback(page) {
  149. // 此处可以继续请求其他接口
  150. // if(page.num == 1){
  151. // // 请求其他接口...
  152. // }
  153. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  154. // if(!this.hasTypeId){
  155. // this.shopNewsType();
  156. // return // 此处return,先获取xx
  157. // }
  158. let pageNum = page.num; // 页码, 默认从1开始
  159. let pageSize = page.size; // 页长, 默认每页10条
  160. let params = {
  161. pageNum : page.num,
  162. pageSize : page.size,
  163. status : this.tabsList[this.tabsCurrent]?.status||'',
  164. // status : this.tabsList[this.tabsCurrent].status,
  165. }
  166. // console.log('this.params',params);
  167. this.$u.api.orderList(params).then(data => {
  168. this.hasfetch = true;
  169. console.log('data',JSON.parse(JSON.stringify(data)));
  170. // 接口返回的当前页数据列表 (数组)
  171. let curPageData = data.data.rows;
  172. // console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  173. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  174. let curPageLen = curPageData.length;
  175. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  176. // let totalPage = data.data.data.totalPage;
  177. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  178. let totalSize = data.data.total;
  179. // 接口返回的是否有下一页 (true/false)
  180. // let hasNext = data.xxx;
  181. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  182. //设置列表数据
  183. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  184. this.dataList = this.dataList.concat(curPageData); //追加新数据
  185. // 请求成功,隐藏加载状态
  186. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  187. // this.mescroll.endByPage(curPageLen, totalPage);
  188. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  189. this.mescroll.endBySize(curPageLen, totalSize);
  190. }).catch(err => {
  191. this.mescroll.endErr()
  192. console.log(err)
  193. });
  194. },
  195. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  196. reloadList() {
  197. this.mescroll.resetUpScroll();
  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. };
  221. // console.log('funObj[fun]',funObj[fun]);
  222. if (fun in funObj) {
  223. funObj[fun](item);
  224. }
  225. },
  226. pay(item){
  227. console.log('pay',item);
  228. uni.$u.route('/shopping/pay', {
  229. orderId: item.id,
  230. // openid: that.vuex_wechatOpenid,
  231. payAmount:item.orderPrice
  232. });
  233. },
  234. logistics(item){
  235. // console.log('logistics',item);
  236. uni.$u.route('/shopping/distribution', {
  237. orderId: item.id
  238. });
  239. },
  240. evaluate(item){
  241. // console.log('logistics',item);
  242. uni.$u.route('/shopping/evaluate', {
  243. id: item.id
  244. });
  245. },
  246. refund(item){
  247. // console.log('logistics',item);
  248. uni.$u.route('/shopping/refund', {
  249. id: item.id
  250. });
  251. },
  252. cancelOrder(item){
  253. let that = this;
  254. uni.showModal({
  255. title: '提示',
  256. content: '确认取消吗!',
  257. success: res => {
  258. if (res.confirm) {
  259. this.$u.api.cancelOrder({orderId:item.id}).then(res=>{
  260. this.$refs.uToast.show({
  261. message:res.msg,
  262. complete() {
  263. that.reloadList();
  264. }
  265. });
  266. // uni.$u.toast(res.msg);
  267. console.log('res',res.data);
  268. }).catch(err=>{
  269. console.log('cancelOrder',err);
  270. })
  271. }
  272. }
  273. });
  274. // console.log('logistics',item);
  275. },
  276. viewRefund(item){
  277. uni.$u.route('/shopping/viewRefund', {
  278. orderId: item.id
  279. });
  280. },
  281. confirmReceipt(item){
  282. let that = this;
  283. uni.showModal({
  284. title: '提示',
  285. content: '确认收货吗!',
  286. success: res => {
  287. if (res.confirm) {
  288. this.$u.api.confirmReceipt({orderId:item.id}).then(res=>{
  289. uni.showToast({
  290. title:res.msg,
  291. duration:2000,
  292. complete() {
  293. that.reloadList();
  294. }
  295. });
  296. console.log('res',res.data);
  297. }).catch(err=>{
  298. console.log('confirmReceipt',err);
  299. })
  300. }
  301. }
  302. })
  303. },
  304. statisticsOrder(){
  305. this.$u.api.statisticsOrder().then(res=>{
  306. let data = res.data || {};
  307. this.orderBadge = Object.assign(this.orderBadge,data);
  308. let {noPayNum,deliverNum,collectNum,commentNum,refundNum} = res.data;
  309. let noPayNumindex = this.tabsList.findIndex(item => item.status == 0);
  310. if(noPayNum>0){
  311. this.tabsList[1].badge.isDot = true;
  312. }
  313. if(deliverNum>0){
  314. this.tabsList[2].badge.isDot = true;
  315. }
  316. if(collectNum>0){
  317. this.tabsList[3].badge.isDot = true;
  318. }
  319. if(commentNum>0){
  320. this.tabsList[4].badge.isDot = true;
  321. }
  322. if(refundNum>0){
  323. this.tabsList[5].badge.isDot = true;
  324. }
  325. // console.log('statisticsOrder',res.data);
  326. // console.log('this.orderBadge',this.orderBadge);
  327. }).catch(err=>{
  328. console.log('memberInfo',err.data);
  329. })
  330. }
  331. }
  332. }
  333. </script>
  334. <style>
  335. page{
  336. background-color: #F5F5F5;
  337. }
  338. </style>
  339. <style lang="scss" scoped>
  340. .tabs-wrap{
  341. background-color: #fff;
  342. margin-bottom: 10rpx;
  343. }
  344. .list-item{
  345. overflow: hidden;
  346. width: 48%;
  347. margin-bottom: 30rpx;
  348. background-color: #fff;
  349. .image-wrap{
  350. margin-bottom: 20rpx;
  351. }
  352. }
  353. .order-item{
  354. margin-bottom: 20rpx;
  355. background-color: #fff;
  356. padding: 30rpx 20rpx;
  357. border-radius: 8rpx;
  358. .top{
  359. margin-bottom: 20rpx;
  360. padding-bottom: 20rpx;
  361. font-size: 24rpx;
  362. font-weight: 400;
  363. color: #999999;
  364. border-bottom: 0.5px solid #eee;
  365. .status{font-size: 24rpx;}
  366. }
  367. .center{
  368. margin-bottom: 20rpx;
  369. padding-bottom: 20rpx;
  370. border-bottom: 0.5px solid #eee;
  371. .goods{
  372. padding: 20rpx 0;
  373. &:not(:last-child){
  374. border-bottom: 0.5px solid #eee;
  375. }
  376. }
  377. .text{
  378. margin-left: 20rpx;
  379. .specification{
  380. font-size: 24rpx;
  381. font-weight: 400;
  382. color: #999999;
  383. margin-top: 16rpx;
  384. }
  385. }
  386. .right{
  387. text-align: right;
  388. /deep/.u-icon{
  389. margin-bottom: 10rpx;
  390. justify-content: flex-end;
  391. }
  392. }
  393. }
  394. .order-price{
  395. text-align: right;
  396. margin-bottom: 20rpx;
  397. font-weight: 600;
  398. }
  399. .bottom{
  400. font-size: 24rpx;
  401. .left{color: #333;}
  402. .right{
  403. .btn{
  404. padding: 12rpx 20rpx;
  405. border: 1px solid #333;
  406. text-align: center;
  407. margin-left: 20rpx;
  408. border-radius: 28rpx;
  409. &.red{border-color: #FF3C3F;}
  410. &.green{color: #00A447;border-color: #00A447;}
  411. }
  412. }
  413. }
  414. &.status-0{.status{color:#FF3C3F;}}
  415. &.status-1{.status{color:#FF3C3F;}}
  416. &.status-2{.status{color:#0099EB;}}
  417. &.status-3{.status{color:#00A447;}}
  418. &.status-4{.status{color:#FF3C3F;}}
  419. &.status-5{.status{color:#FF3C3F;}}
  420. &.status-6{.status{color:#FF3C3F;}}
  421. &.status-7{.status{color:#FFB100;}}
  422. }
  423. </style>