index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.getrefreshData()
  44. })
  45. this.init()
  46. this.getDataFn()
  47. },
  48. // 上拉触底加载更多触发事件
  49. onReachBottom() {
  50. if (this.reachflag) {
  51. this.pageNum++
  52. this.getrefreshData()
  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.getrefreshData()
  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. getrefreshData(){
  91. this.pageNum=1;
  92. this.list=[];
  93. this.reachflag=true;
  94. this.getDataFn()
  95. },
  96. getDataFn(){
  97. var params={
  98. pageSize:this.pageSize,
  99. pageNum: this.pageNum,
  100. residentPhone:this.phonenumber
  101. }
  102. carList(params).then(res=>{
  103. if(res.code==200){
  104. if (res.rows.length < this.pageSize) {
  105. this.reachflag = false
  106. this.wtdt = '到底了~';
  107. } else {
  108. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum - 1)
  109. if (num < res.total) {
  110. this.reachflag = true
  111. this.wtdt = ''
  112. } else {
  113. this.reachflag = false
  114. this.wtdt = '到底了~';
  115. }
  116. }
  117. var newArr=JSON.parse(JSON.stringify(res.rows))
  118. newArr.forEach(ite=>{
  119. ite.right=0;
  120. })
  121. if (this.pageNum == 1) {
  122. this.list = newArr;
  123. } else {
  124. this.list = this.list.concat(newArr)
  125. }
  126. }else{
  127. this.$toast(res.msg)
  128. }
  129. })
  130. },
  131. }
  132. }
  133. </script>
  134. <style>
  135. page{background: #F3F3F0;}
  136. </style>
  137. <style lang="scss" scoped>
  138. .carbox{display: flex;flex-direction: column;min-height: 100vh;padding: 22rpx 18rpx 100rpx;
  139. .cartop{overflow: auto;}
  140. .cartips{background: #FFFFFF;border-radius: 20rpx;height: 98rpx;padding: 0 24rpx;
  141. image{width: 16rpx;height: 28rpx;flex: 0 0 auto;margin-left: 20rpx;}
  142. .tit{font-weight: bold;font-size: 26rpx;color: #272727;}
  143. }
  144. }
  145. </style>