index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. userId:this.$store.state.user.userId,
  35. phonenumber:this.$store.state.user.phonenumber,
  36. }
  37. },
  38. onUnload() {
  39. uni.$off('carlist')
  40. },
  41. onLoad: function() {
  42. uni.$on('carlist',(res)=>{
  43. this.getDataFn()
  44. })
  45. this.init()
  46. this.getDataFn()
  47. },
  48. // 上拉触底加载更多触发事件
  49. onReachBottom() {
  50. if (this.reachflag) {
  51. this.pageNum++
  52. this.getDataFn()
  53. }
  54. },
  55. methods:{
  56. checkPermi, checkRole,
  57. init(){
  58. // 车型
  59. getDictionaryFn('cartype').then(res=>{
  60. if(res.code==200){
  61. this.clcxList = res.data.map(v => {
  62. return {
  63. dictLabel: v.dictLabel,
  64. dictValue: v.dictValue
  65. }
  66. })
  67. }
  68. })
  69. },
  70. getDelFn(data){
  71. var that=this;
  72. carDel(data).then(res=>{
  73. if(res.code==200){
  74. this.$toast("删除成功");
  75. setTimeout(function(){
  76. that.getDataFn()
  77. },1500)
  78. }
  79. })
  80. },
  81. getAddFn(){
  82. this.$tab.navigateTo("/mine/pages/car/addcar")
  83. },
  84. getDetail(id){
  85. this.$tab.navigateTo("/mine/pages/car/addcar?id="+id)
  86. },
  87. getChargeFn(){
  88. this.$tab.navigateTo("/mine/pages/car/charge")
  89. },
  90. getDataFn(){
  91. var params={
  92. pageSize:this.pageSize,
  93. pageNum: this.pageNum,
  94. residentPhone:this.phonenumber
  95. }
  96. carList(params).then(res=>{
  97. if(res.code==200){
  98. if (res.rows.length < this.pageSize) {
  99. this.reachflag = false
  100. this.wtdt = '到底了~';
  101. } else {
  102. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum - 1)
  103. if (num < res.total) {
  104. this.reachflag = true
  105. this.wtdt = ''
  106. } else {
  107. this.reachflag = false
  108. this.wtdt = '到底了~';
  109. }
  110. }
  111. var newArr=JSON.parse(JSON.stringify(res.rows))
  112. newArr.forEach(ite=>{
  113. ite.right=0;
  114. })
  115. if (this.pageNum == 1) {
  116. this.list = newArr;
  117. } else {
  118. this.list = this.list.concat(newArr)
  119. }
  120. }else{
  121. this.$toast(res.msg)
  122. }
  123. })
  124. },
  125. }
  126. }
  127. </script>
  128. <style>
  129. page{background: #F3F3F0;}
  130. </style>
  131. <style lang="scss" scoped>
  132. .carbox{display: flex;flex-direction: column;min-height: 100vh;padding: 22rpx 18rpx 100rpx;
  133. .cartop{overflow: auto;}
  134. .cartips{background: #FFFFFF;border-radius: 20rpx;height: 98rpx;padding: 0 24rpx;
  135. image{width: 16rpx;height: 28rpx;flex: 0 0 auto;margin-left: 20rpx;}
  136. .tit{font-weight: bold;font-size: 26rpx;color: #272727;}
  137. }
  138. }
  139. </style>