index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view class="carbox">
  3. <view class="flex1 cartop">
  4. <box-list :datainfo="list" type="mycar" :clcxList="clcxList" @getDetail="getDetail" @getDelFn="getDelFn"></box-list>
  5. <view class="cartips flexc mt16 mb16" @click="getChargeFn">
  6. <view class="tit flex1">当前有车辆<text class="co025">充电中…</text></view>
  7. <image :src="rimg"></image>
  8. </view>
  9. </view>
  10. <view class="plr12 flex0">
  11. <view class="rhbtn" @click="getAddFn">添加车辆</view>
  12. </view>
  13. <loading></loading>
  14. </view>
  15. </template>
  16. <script>
  17. import config from '@/config'
  18. const baseUrl = config.baseUrl
  19. import boxList from "@/mine/components/box/list.vue"
  20. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  21. import {carList,carDel} from "@/api/work/car.js"
  22. import {getDictionaryFn} from "@/api/system/user.js"
  23. export default{
  24. components:{boxList},
  25. data(){
  26. return{
  27. rimg: require('@/mine/static/house/rimg.png'),
  28. list:[],
  29. pageSize: 10,
  30. pageNum: 1,
  31. reachflag: true,
  32. wtdt:'',
  33. clcxList:[]
  34. }
  35. },
  36. onUnload() {
  37. uni.$off('carlist')
  38. },
  39. onLoad: function() {
  40. uni.$on('carlist',(res)=>{
  41. this.getDataFn()
  42. })
  43. this.init()
  44. this.getDataFn()
  45. },
  46. // 上拉触底加载更多触发事件
  47. onReachBottom() {
  48. if (this.reachflag) {
  49. this.pageNum++
  50. this.getDataFn()
  51. }
  52. },
  53. methods:{
  54. checkPermi, checkRole,
  55. init(){
  56. // 车型
  57. getDictionaryFn('cartype').then(res=>{
  58. if(res.code==200){
  59. this.clcxList = res.data.map(v => {
  60. return {
  61. dictLabel: v.dictLabel,
  62. dictValue: v.dictValue
  63. }
  64. })
  65. }
  66. })
  67. },
  68. getDelFn(data){
  69. var that=this;
  70. carDel(data).then(res=>{
  71. if(res.code==200){
  72. this.$toast("删除成功");
  73. setTimeout(function(){
  74. that.getDataFn()
  75. },1500)
  76. }
  77. })
  78. },
  79. getAddFn(){
  80. this.$tab.navigateTo("/mine/pages/car/addcar")
  81. },
  82. getDetail(id){
  83. this.$tab.navigateTo("/mine/pages/car/addcar?id="+id)
  84. },
  85. getChargeFn(){
  86. this.$tab.navigateTo("/mine/pages/car/charge")
  87. },
  88. getDataFn(){
  89. var params={
  90. pageSize:this.pageSize,
  91. pageNum: this.pageNum,
  92. }
  93. carList(params).then(res=>{
  94. if(res.code==200){
  95. if (res.rows.length < this.pageSize) {
  96. this.reachflag = false
  97. this.wtdt = '到底了~';
  98. } else {
  99. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum - 1)
  100. if (num < res.total) {
  101. this.reachflag = true
  102. this.wtdt = ''
  103. } else {
  104. this.reachflag = false
  105. this.wtdt = '到底了~';
  106. }
  107. }
  108. var newArr=JSON.parse(JSON.stringify(res.rows))
  109. newArr.forEach(ite=>{
  110. ite.right=0;
  111. })
  112. if (this.pageNum == 1) {
  113. this.list = newArr;
  114. } else {
  115. this.list = this.list.concat(newArr)
  116. }
  117. }else{
  118. this.$toast(res.msg)
  119. }
  120. })
  121. },
  122. }
  123. }
  124. </script>
  125. <style>
  126. page{background: #F3F3F0;}
  127. </style>
  128. <style lang="scss" scoped>
  129. .carbox{display: flex;flex-direction: column;min-height: 100vh;padding: 22rpx 18rpx 100rpx;
  130. .cartop{overflow: auto;}
  131. .cartips{background: #FFFFFF;border-radius: 20rpx;height: 98rpx;padding: 0 24rpx;
  132. image{width: 16rpx;height: 28rpx;flex: 0 0 auto;margin-left: 20rpx;}
  133. .tit{font-weight: bold;font-size: 26rpx;color: #272727;}
  134. }
  135. }
  136. </style>