monthly.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <!-- 包月 -->
  3. <view class="monthly">
  4. <u-navbar
  5. title-color="#fff"
  6. :custom-back="customBack"
  7. :border-bottom="false"
  8. back-icon-color="#CCE8FF"
  9. :background="{background: '#008CFF' }" title="我的包月"></u-navbar>
  10. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" >
  11. <!-- <scroll-view scroll-y style="height: 100%; width: 100%;" v-for="(monthlyItem, index) in monthlyList" :key="monthlyItem.id"> -->
  12. <view class="monthly-list">
  13. <view class="monthly-list-item" v-for="(monthlyItem, index) in monthlyList" :key="monthlyItem.id">
  14. <view class="monthly-list-item-top">
  15. <view class="mlit-left">
  16. <view>{{monthlyItem.vehicleNo}}</view>
  17. <view>{{monthlyItem.roadName}}</view>
  18. </view>
  19. <view class="mlit-right u-flex">
  20. <view class="mlit-right-item fee-status" v-if="monthlyItem.feeStatus === 0">未缴费</view>
  21. <view class="mlit-right-item fee-status" v-if="monthlyItem.feeStatus === 1">已缴费</view>
  22. <view class="mlit-right-item" v-if="monthlyItem.energyType === 1">汽油车</view>
  23. <view class="mlit-right-item" v-if="monthlyItem.energyType === 2">新能源</view>
  24. </view>
  25. </view>
  26. <view class="monthly-list-item-bottom" >
  27. <view class="mlib-item">
  28. <view>包期</view>:
  29. <view>{{(monthlyItem.beginTime.split('-')).join('.')}}-{{(monthlyItem.endTime.split('-')).join('.')}}</view>
  30. </view>
  31. <view class="mlib-item">
  32. <view>剩余天数</view>:
  33. <view>{{monthlyItem.surplusDays}}天</view>
  34. </view>
  35. </view>
  36. <view v-if="monthlyItem.feeStatus=='0'" class="button-wrap u-flex u-row-right">
  37. <view class="tool-btn"
  38. :class="{'tool-btn-cancel':monthlyItem.feeStatus=='0'}"
  39. v-if="monthlyItem.feeStatus=='0'"
  40. @click="cancelMonth(monthlyItem.monthId)">取消订单</view>
  41. <!-- <u-button class="btn" v-if="monthlyItem.feeStatus=='0'" type="error" size="mini" @click="cancelMonth(monthlyItem.monthId)">取消缴费</u-button> -->
  42. </view>
  43. </view>
  44. </view>
  45. <!-- </scroll-view> -->
  46. </mescroll-body>
  47. <u-modal v-model="canclShow" content="确认取消该订单?" @confirm="confirm" :show-cancel-button="true"></u-modal>
  48. <u-toast ref="uToast" />
  49. </view>
  50. </template>
  51. <script>
  52. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  53. export default {
  54. mixins: [MescrollMixin], // 使用mixin
  55. data() {
  56. return {
  57. id:'',
  58. canclShow: false,
  59. monthlyList: [],
  60. monthList:'',
  61. beginTime:'',
  62. endTime:'',
  63. time:[],
  64. }
  65. },
  66. methods: {
  67. customBack(){
  68. this.$u.route({
  69. type:'switchTab',
  70. url: 'pages/center/index'
  71. });
  72. },
  73. /*下拉刷新的回调*/
  74. downCallback(){
  75. // 第2种: 下拉刷新和上拉加载调同样的接口, 则不用第1种, 直接mescroll.resetUpScroll()即可
  76. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  77. },
  78. /*上拉加载的回调*/
  79. upCallback(page) {
  80. let pageNum = page.num; // 页码, 默认从1开始
  81. let pageSize = page.size; // 页长, 默认每页10条
  82. // this.getMessageList()
  83. this.$u.api.getMonthList({pageSize:pageSize ,pageNum: pageNum})
  84. .then(res=>{
  85. if(res.code == 200){
  86. console.log('res',res)
  87. // 接口返回的当前页数据列表 (数组)
  88. let curPageData = res.data.rows;
  89. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  90. let curPageLen = curPageData.length;
  91. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  92. let totalPage = res.data.pages;
  93. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  94. let totalSize = res.data.total;
  95. // 接口返回的是否有下一页 (true/false)
  96. // let hasNext = data.pages;
  97. //设置列表数据
  98. if(page.num == 1) this.monthlyList = []; //如果是第一页需手动置空列表
  99. this.monthlyList = this.monthlyList.concat(curPageData); //追加新数据
  100. // 请求成功,隐藏加载状态
  101. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  102. this.mescroll.endByPage(curPageLen, totalPage);
  103. setTimeout(()=>{
  104. this.mescroll.endSuccess(curPageLen)
  105. },20)
  106. this.monthList=[],
  107. res.data.rows.forEach(item => {
  108. const obj = {
  109. beginTime: item.beginTime,
  110. endTime: item.endTime,
  111. }
  112. this.monthList.push(obj)
  113. console.log(obj)
  114. });
  115. this.time = this.monthList[0]
  116. let Date1 = this.time.beginTime;
  117. let Date2 = this.time.endTime;
  118. // Date1 = Date1.valueOf() + 24 * 60 * 60 * 1000
  119. Date1 = new Date(Date1)
  120. const year = Date1.getFullYear()
  121. const month = Date1.getMonth()+1
  122. const day = Date1.getDate()
  123. Date2 = new Date(Date2)
  124. const year2 = Date2.getFullYear()
  125. const month2 = Date2.getMonth()+1
  126. const day2 = Date2.getDate()
  127. this.beginTime = year + '.' + month + '.' + day
  128. console.log(this.beginTime)
  129. this.endTime = year2 + '.' + month2 + '.' + day2
  130. }else{
  131. this.mescroll.endErr()
  132. }
  133. }).catch(err=>{
  134. // console.log('err',err);
  135. // this.$refs.uToast.show({
  136. // title: err.msg,
  137. // type: 'error',
  138. // });
  139. });
  140. },
  141. cancelMonth(monthId){
  142. this.id=monthId;
  143. this.canclShow = true;
  144. console.log('monthId',monthId)
  145. },
  146. confirm(){
  147. this.$u.api.cancelMonth({monthId: this.id})
  148. .then(res=>{
  149. if(res.code === 200){
  150. this.$refs.uToast.show({
  151. title: res.msg,
  152. type: 'success',
  153. });
  154. this.downCallback()
  155. }else{
  156. }
  157. }).catch(err=>{
  158. this.$refs.uToast.show({
  159. title: err.msg,
  160. type: 'error',
  161. });
  162. })
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. @import './monthly.scss';
  169. </style>