monthly1.vue 6.3 KB

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