order.vue 11 KB

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