order.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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="#EE0D0D"
  15. :current="tabsCurrent"
  16. :activeStyle="{color:'#EE0D0D','font-weight': '600','font-size':'30rpx'}"
  17. :inactiveStyle="{color:'#7F7F7F'}"
  18. itemStyle="width:20%;box-sizing:border-box;padding:24rpx"
  19. @click="tabsClick"></u-tabs>
  20. </view>
  21. <view class="page-wrap">
  22. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  23. <view class="order">
  24. <view v-for="(item,index) in orderListWithClass" class="order-item"
  25. :class="item.class"
  26. @click="goOrderDetails(item)" :key="item.id">
  27. <view class="top u-flex u-row-between">
  28. <text>{{item.theatreName}}</text>
  29. <text>{{item.status|filterOrderState}}</text>
  30. </view>
  31. <view class="info u-flex u-col-top">
  32. <image class="img" :src="item.performImg"></image>
  33. <view class="text">
  34. <view class="name">{{item.performName}} - {{item.goodsName}}</view>
  35. <view class="time">{{item.performDate}} {{item.performTimeStart}}</view>
  36. <!-- <view class="position">{{item.performDate}}</view> -->
  37. <view class="statistics">
  38. <text>共{{item.viewerNum}}张</text>
  39. <text class="label">合计:</text>
  40. <text class="price">¥{{item.realPrice}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="btn-wrap u-flex u-row-right">
  45. <view
  46. class="btn"
  47. :class="btn.class"
  48. @click.stop="clickEven(btn.fun,item)"
  49. v-for="(btn,index) in statusBtn[item.status]" :key="index">
  50. {{btn.name}}
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </mescroll-body>
  56. </view>
  57. <u-toast ref="uToast"></u-toast>
  58. <tabbar :tabbarIndexProps="1" />
  59. </view>
  60. </template>
  61. <script>
  62. import tabbar from "../components/tabbar.vue";
  63. // 引入mescroll-mixins.js
  64. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  65. export default {
  66. mixins: [MescrollMixin], // 使用mixin
  67. components:{
  68. tabbar
  69. },
  70. data() {
  71. return {
  72. staticUrl:this.$commonConfig.staticUrl,
  73. goodsKey:1,
  74. hasfetch:false,
  75. tabsCurrent:1,
  76. tabsList:[
  77. {name:'全部',status:null,},
  78. {name:'待支付',status:'0',badge:{isDot:false,value:null}},
  79. {name:'待使用',status:'3',badge:{isDot:false,value:null}},
  80. {name:'已完成',status:'7',badge:{isDot:false,value:null}},
  81. {name:'售后',status:'4,5,6',badge:{isDot:false,value:null}}
  82. ],
  83. status:'',
  84. dataList:[],
  85. statusBtn:{// 状态(0待支付,2超时取消,3支付完成,待使用,4退款中,5己退款,6退款失败,7己使用,8己超期 9关闭)
  86. 0:[{name:'取消订单',fun:'cancelOrder',class:''},{name:'去支付',fun:'pay',class:'red'}],
  87. 1:[],
  88. 2:[],
  89. 3:[{name:'出示二维码',fun:'goOrderDetails',class:'red'}],
  90. //,{name:'评价',fun:'evaluate',class:'green'}
  91. 4:[],
  92. 5:[],
  93. 6:[],
  94. // ,{name:'查看评价',fun:'viewEvaluate',class:'green'}
  95. 7:[],
  96. 8:[],
  97. 9:[]
  98. },
  99. orderBadge:{
  100. noPayNum:0,
  101. deliverNum:0,
  102. collectNum:0,
  103. commentNum:0,
  104. refundNum:0,
  105. },
  106. templateIdList:[],//微信小程序订阅消息
  107. }
  108. },
  109. computed: {
  110. orderListWithClass() {
  111. return this.dataList.map(order => {
  112. // let spliceData = order.detailList.splice(0,2);
  113. // let moreData = order.detailList.splice(2,order.detailList.length);
  114. // let moreData = order.detailList.slice(2);
  115. // if(order.detailList.length>2){
  116. // moreData = order.detailList;
  117. // }
  118. return {
  119. ...order,
  120. // spliceData:spliceData,
  121. // moreData:moreData,
  122. // showMore:false,
  123. class: {
  124. 0: 'status-0',
  125. 1: 'status-1',
  126. 2: 'status-2',
  127. 3: 'status-3',
  128. 4: 'status-4',
  129. 5: 'status-5',
  130. 6: 'status-6',
  131. 7: 'status-7',
  132. 8: 'status-8'
  133. }[order.status] || ''
  134. }
  135. })
  136. }
  137. },
  138. onLoad(page) {
  139. // console.log('page',page);
  140. const status = page.status;
  141. const index = this.tabsList.findIndex(item => item.status === status);
  142. this.tabsCurrent = index>=0?index:0;
  143. this.getTemplateIdList();//获取模板列表
  144. },
  145. onShow() {
  146. setTimeout(()=>{
  147. this.hasfetch&&this.reloadList()
  148. },500);
  149. // this.statisticsOrder();
  150. },
  151. methods: {
  152. leftClick(){
  153. uni.reLaunch({url: '/center/center'});
  154. },
  155. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  156. downCallback(){
  157. this.mescroll.resetUpScroll();
  158. },
  159. /*上拉加载的回调*/
  160. upCallback(page) {
  161. // this.statisticsOrder();
  162. // 此处可以继续请求其他接口
  163. // if(page.num == 1){
  164. // // 请求其他接口...
  165. // }
  166. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  167. // if(!this.hasTypeId){
  168. // this.shopNewsType();
  169. // return // 此处return,先获取xx
  170. // }
  171. let pageNum = page.num; // 页码, 默认从1开始
  172. let pageSize = page.size; // 页长, 默认每页10条
  173. let params = {
  174. pageNum : page.num,
  175. pageSize : page.size,
  176. statusIn : this.tabsList[this.tabsCurrent]?.status||'',
  177. userid:this.vuex_member_info.id
  178. // status : this.tabsList[this.tabsCurrent].status,
  179. }
  180. // console.log('this.params',params);
  181. this.$u.api.orderList(params).then(data => {
  182. this.hasfetch = true;
  183. console.log('data',JSON.parse(JSON.stringify(data)));
  184. // 接口返回的当前页数据列表 (数组)
  185. let curPageData = data.data.rows;
  186. // console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  187. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  188. let curPageLen = curPageData.length;
  189. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  190. // let totalPage = data.data.data.totalPage;
  191. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  192. let totalSize = data.data.total;
  193. // 接口返回的是否有下一页 (true/false)
  194. // let hasNext = data.xxx;
  195. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  196. //设置列表数据
  197. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  198. this.dataList = this.dataList.concat(curPageData); //追加新数据
  199. // 请求成功,隐藏加载状态
  200. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  201. // this.mescroll.endByPage(curPageLen, totalPage);
  202. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  203. this.mescroll.endBySize(curPageLen, totalSize);
  204. }).catch(err => {
  205. this.mescroll.endErr()
  206. console.log(err)
  207. });
  208. },
  209. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  210. reloadList() {
  211. this.mescroll.resetUpScroll();
  212. },
  213. tabsClick(item){
  214. // this.status = item.status;
  215. this.tabsCurrent = item.index;
  216. this.reloadList()
  217. // console.log('item',item);
  218. },
  219. goOrderDetails(item){
  220. uni.$u.route('/center/orderdetails', {
  221. id: item.id
  222. });
  223. },
  224. toggleMore(item,index){
  225. // console.log('toggleMore',item);
  226. this.orderListWithClass[index].showMore = !this.orderListWithClass[index].showMore
  227. this.goodsKey++;
  228. },
  229. clickEven(fun,item){
  230. // console.log('fun',fun);
  231. let funObj = {
  232. pay: this.pay,
  233. goOrderDetails:this.goOrderDetails,
  234. evaluate:this.evaluate,
  235. refund:this.refund,
  236. cancelOrder:this.cancelOrder,
  237. viewRefund:this.viewRefund,
  238. confirmReceipt:this.confirmReceipt,
  239. viewEvaluate:this.viewEvaluate
  240. };
  241. // console.log('funObj[fun]',funObj[fun]);
  242. if (fun in funObj) {
  243. funObj[fun](item);
  244. }
  245. },
  246. getTemplateIdList(){
  247. this.$u.api.templateIdList({templateLabel:'order_pay'}).then(res=>{
  248. console.log('getTemplateIdList',res.data);
  249. this.templateIdList = res.data.list.map(item=>{
  250. return item.templateId
  251. });
  252. // if(this.templateIdList.length>0){
  253. // this.templateEven();
  254. // }
  255. }).catch(err=>{
  256. console.log('getTemplateIdList',err);
  257. })
  258. },
  259. pay(item){
  260. console.log('pay',item);
  261. // this.gotoPay(item.id);
  262. this.setTemplate(item.id);
  263. // uni.$u.route('/shopping/pay', {
  264. // orderId: item.id,
  265. // // openid: that.vuex_wechatOpenid,
  266. // payAmount:item.orderPrice
  267. // });
  268. },
  269. evaluate(item){
  270. // console.log('logistics',item);
  271. uni.$u.route('/shopping/evaluate', {
  272. id: item.id
  273. });
  274. },
  275. comment(orderId,orderDetailId,goodsId){
  276. uni.$u.route('/shopping/addcomment', {
  277. orderId,
  278. orderDetailId,
  279. goodsId
  280. });
  281. },
  282. viewComment(orderDetailId,goodsId,goods){
  283. uni.$u.route('/shopping/viewcomment', {
  284. orderDetailId,
  285. goodsId,
  286. goods:JSON.stringify(goods)
  287. });
  288. },
  289. refund(item){
  290. // console.log('logistics',item);
  291. uni.$u.route('/shopping/refund', {
  292. id: item.id
  293. });
  294. },
  295. cancelOrder(item){
  296. let that = this;
  297. uni.showModal({
  298. title: '提示',
  299. content: '确认取消吗!',
  300. success: res => {
  301. if (res.confirm) {
  302. this.$u.api.cancelOrder({orderId:item.id}).then(res=>{
  303. this.$refs.uToast.show({
  304. message:res.msg,
  305. complete() {
  306. that.reloadList();
  307. }
  308. });
  309. // uni.$u.toast(res.msg);
  310. console.log('res',res.data);
  311. }).catch(err=>{
  312. console.log('cancelOrder',err);
  313. })
  314. }
  315. }
  316. });
  317. // console.log('logistics',item);
  318. },
  319. viewRefund(item){
  320. uni.$u.route('/center/viewRefund', {
  321. orderId: item.id
  322. });
  323. },
  324. confirmReceipt(item){
  325. let that = this;
  326. uni.showModal({
  327. title: '提示',
  328. content: '确认收货吗!',
  329. success: res => {
  330. if (res.confirm) {
  331. this.$u.api.confirmReceipt({orderId:item.id}).then(res=>{
  332. uni.showToast({
  333. title:res.msg,
  334. duration:2000,
  335. complete() {
  336. that.reloadList();
  337. }
  338. });
  339. console.log('res',res.data);
  340. }).catch(err=>{
  341. console.log('confirmReceipt',err);
  342. })
  343. }
  344. }
  345. })
  346. },
  347. viewEvaluate(item){
  348. uni.$u.route('/shopping/orderdetails', {
  349. id: item.id
  350. });
  351. },
  352. // 设置小程序订阅消息
  353. setTemplate(orderId) {
  354. let that = this;
  355. console.log('templateIdList',this.templateIdList);
  356. uni.requestSubscribeMessage({
  357. tmplIds: that.templateIdList,
  358. success (res) {
  359. // that.gotoPay();
  360. console.log("success:",res);
  361. },
  362. fail (res) {
  363. console.log("fail:",res);
  364. },
  365. complete (res) {
  366. that.gotoPay(orderId);
  367. console.log("complete:",res);
  368. }
  369. })
  370. },
  371. gotoPay(orderId){
  372. this.$u.api.gotoPay({orderId:orderId,openid:''}).then(res=>{
  373. this.payResult = res.data.payInfo;
  374. this.payResult.package = res.data.payInfo.packageValue;
  375. this.wxPay()
  376. // if(this.params.paymentMode==1||this.params.paymentMode==4){
  377. // this.wxPay()
  378. // }else{
  379. // uni.$u.route('/shopping/paysuccess');
  380. // }
  381. console.log('gotoPayres',res.data);
  382. }).catch(err=>{
  383. this.paypass = '';
  384. this.checkPassShow = false;
  385. console.log('gotoPay',err);
  386. })
  387. },
  388. wxPay(){
  389. let that = this;
  390. uni.requestPayment({
  391. ... this.payResult,
  392. "provider": "wxpay",
  393. "orderInfo": {
  394. // "appid": "wx499********7c70e", // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  395. // "noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串
  396. // "package": "Sign=WXPay", // 固定值
  397. // "partnerid": "148*****52", // 微信支付商户号
  398. // "prepayid": "wx202254********************fbe90000", // 统一下单订单号
  399. // "timestamp": 1597935292, // 时间戳(单位:秒)
  400. // "sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名,这里用的 MD5/RSA 签名
  401. },
  402. success(res) {
  403. that.payQuery();
  404. },
  405. fail(e) {
  406. console.log('wxPayfail',e);
  407. }
  408. })
  409. },
  410. payQuery(){
  411. let that = this;
  412. let retryCount = 0;
  413. let maxRetryCount = 5; // 设置最大重试次数
  414. let interval = 2000; // 设置间隔时间为2秒
  415. let timeout = 10000; // 设置超时时间为10秒
  416. let timer;
  417. uni.showLoading({
  418. title:'支付结果查询中'
  419. })
  420. timer = setInterval(() => {
  421. retryCount++;
  422. if (retryCount > maxRetryCount || retryCount * interval > timeout) {
  423. clearInterval(timer);
  424. uni.hideLoading();
  425. console.log("支付查询超时或达到最大重试次数");
  426. // 在这里添加超时或达到最大重试次数的处理逻辑
  427. this.reloadList()
  428. } else {
  429. console.log("第" + retryCount + "次查询");
  430. // 调用查询支付状态的方法
  431. // 如果支付状态为成功,则清除定时器并处理成功的逻辑
  432. // 如果支付状态为失败,则清除定时器并处理失败的逻辑
  433. this.$u.api.payQuery({orderId:this.orderId}).then(res=>{
  434. // 0-未支付 1-已支付 2-支付中 3-支付失败 4-支付退款
  435. let payStatus = res.data.payStatus;
  436. if(payStatus===1){
  437. uni.$u.route('/center/paysuccess');
  438. }else if(payStatus===0||payStatus===2){
  439. this.payQuery()
  440. }else if(payStatus===3){
  441. uni.toast('支付失败')
  442. }
  443. clearInterval(timer);
  444. }).catch(err=>{
  445. console.log('payQuery',err);
  446. }).finally(()=>{
  447. uni.hideLoading()
  448. })
  449. }
  450. }, interval);
  451. },
  452. statisticsOrder(){
  453. this.$u.api.statisticsOrder().then(res=>{
  454. let data = res.data || {};
  455. this.orderBadge = Object.assign(this.orderBadge,data);
  456. let {noPayNum,deliverNum,collectNum,commentNum,refundNum} = res.data;
  457. let noPayNumindex = this.tabsList.findIndex(item => item.status == 0);
  458. this.tabsList[1].badge.isDot = false;
  459. this.tabsList[1].badge.value = noPayNum;
  460. this.tabsList[2].badge.isDot = false;
  461. this.tabsList[2].badge.value = deliverNum;
  462. this.tabsList[3].badge.isDot = false;
  463. this.tabsList[3].badge.value = collectNum;
  464. this.tabsList[4].badge.isDot = false;
  465. this.tabsList[4].badge.value = commentNum;
  466. this.tabsList[5].badge.isDot = false;
  467. this.tabsList[5].badge.value = refundNum;
  468. // console.log('statisticsOrder',res.data);
  469. // console.log('this.orderBadge',this.orderBadge);
  470. }).catch(err=>{
  471. console.log('memberInfo',err.data);
  472. })
  473. }
  474. }
  475. }
  476. </script>
  477. <style>
  478. page{
  479. background-color: #F5F5F5;
  480. }
  481. </style>
  482. <style lang="scss" scoped>
  483. .tabs-wrap{
  484. background-color: #fff;
  485. margin-bottom: 10rpx;
  486. }
  487. .list-item{
  488. overflow: hidden;
  489. width: 48%;
  490. margin-bottom: 30rpx;
  491. background-color: #fff;
  492. .image-wrap{
  493. margin-bottom: 20rpx;
  494. }
  495. }
  496. .order-item{
  497. margin-bottom: 20rpx;
  498. background: #FFFFFF;
  499. box-shadow: 0rpx 2rpx 12rpx 0rpx rgba(221,221,221,0.5);
  500. border-radius: 20rpx;
  501. padding: 32rpx;
  502. content-visibility: auto;
  503. contain-intrinsic-size: 346rpx;
  504. .top{
  505. font-size: 24rpx;
  506. font-weight: 400;
  507. color: #7F7F7F;
  508. line-height: 36rpx;
  509. margin-bottom: 36rpx;
  510. }
  511. .info{
  512. margin-bottom: 30rpx;
  513. .img{
  514. width: 180rpx;
  515. height: 160rpx;
  516. }
  517. .text{
  518. font-size: 24rpx;
  519. font-weight: 400;
  520. color: #7F7F7F;
  521. padding-left: 26rpx;
  522. flex: 1;
  523. .name{
  524. font-size: 28rpx;
  525. font-weight: bold;
  526. color: #363636;
  527. margin-bottom: 20rpx;
  528. }
  529. .time{
  530. margin-bottom: 20rpx;
  531. }
  532. .position{
  533. margin-bottom: 20rpx;
  534. }
  535. .statistics{
  536. text-align: right;
  537. }
  538. .label{
  539. font-size: 24rpx;
  540. font-weight: 400;
  541. color: #363636;
  542. margin-left: 10rpx;
  543. }
  544. .price{
  545. font-size: 32rpx;
  546. font-weight: bold;
  547. color: #ED0000;
  548. }
  549. }
  550. }
  551. .btn-wrap{
  552. }
  553. .btn{
  554. padding: 12rpx 40rpx;
  555. border: 1px solid #E5E5E5;
  556. color: #7F7F7F;
  557. text-align: center;
  558. border-radius: 8rpx;
  559. font-size: 24rpx;
  560. &.red{border-color: #ED0000;color: #ED0000;}
  561. &.red.solid{border-color: #ED0000;background-color:#ED0000;color: #fff;}
  562. &.green{color: #00A447;border-color: #00A447;}
  563. &:not(:first-child){
  564. margin-left: 20rpx;
  565. }
  566. }
  567. &.status-0{.status{color:#FF3C3F;}}
  568. &.status-1{.status{color:#FF3C3F;}}
  569. &.status-2{.status{color:#0099EB;}}
  570. &.status-3{.status{color:#00A447;}}
  571. &.status-4{.status{color:#FF3C3F;}}
  572. &.status-5{.status{color:#FF3C3F;}}
  573. &.status-6{.status{color:#FF3C3F;}}
  574. &.status-7{.status{color:#FFB100;}}
  575. }
  576. </style>