room.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <view>
  3. <!-- 筛选标签条 -->
  4. <view class="cu-bar bg-white flex" style="z-index: 100;width: 100%;position: fixed;top: -2rpx;">
  5. <view class="u-line-1" @click="showDown(index)" v-for="(item,index) in filterMenu" :key="index" style="width: 20%;text-align: center;height: 100%;">
  6. <text v-text="data[index]==''?item:data[index]" :class="data[index]==''?'':'text-red'"></text>
  7. <u-icon v-if="index!=4" name="arrow-down-fill" size="20" style="padding-left: 10rpx;"></u-icon>
  8. <text class="cuIcon-filter padding-left-10" v-else></text>
  9. <u-badge :offset="[10, 8]" v-if="index==4" size="mini" type="error" :count="filterCount"></u-badge>
  10. </view>
  11. </view>
  12. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  13. <view style="margin-top: 110rpx;">
  14. <card @delItem="delItem" :list="list"></card>
  15. </view>
  16. </mescroll-body>
  17. <!-- 小区 -->
  18. <u-popup border-radius="60" height="60%" mode="bottom" v-model="popupShow">
  19. <view class="fixed cu-bar search bg-white">
  20. <view class="search-form round">
  21. <text class="cuIcon-search"></text>
  22. <u-input style="width: 90%;" v-model="keyword" type="text" :adjust-position="false" placeholder="请输入关键字搜索" confirm-type="search"/>
  23. </view>
  24. </view>
  25. <scroll-view v-if="!$isEmpty(searchList)" style="padding-top: 110rpx;height: 100%;" :scroll-y="true" >
  26. <view @click="residentailConfirm(item)" hover-class="hoverClass" class="text-center padding-30 solid-bottom" v-for="(item,index) in searchList" :key="index">
  27. <text>{{item.label}}</text>
  28. </view>
  29. <u-divider v-if="searchList.length>=10" height="80">只显示十条数据</u-divider>
  30. </scroll-view>
  31. <u-empty v-else name="search"></u-empty>
  32. </u-popup>
  33. <!-- 楼栋 -->
  34. <u-popup border-radius="60" height="60%" mode="bottom" v-model="buildingShow">
  35. <view class="fixed cu-bar search bg-white">
  36. <view class="search-form round">
  37. <text class="cuIcon-search"></text>
  38. <u-input style="width: 90%;" v-model="buildingKeyWord" type="text" :adjust-position="false" placeholder="请输入关键字搜索" confirm-type="search"/>
  39. </view>
  40. </view>
  41. <scroll-view v-if="!$isEmpty(buildingList)" style="padding-top: 110rpx;height: 100%;" :scroll-y="true" >
  42. <view @click="buildingConfirm(item)" hover-class="hoverClass" class="text-center padding-30 solid-bottom" v-for="(item,index) in buildingList" :key="index">
  43. <text>{{item.name}}</text>
  44. </view>
  45. <u-divider v-if="buildingList.length>=10" height="80">只显示十条数据</u-divider>
  46. </scroll-view>
  47. <u-empty v-else name="search"></u-empty>
  48. </u-popup>
  49. <!-- 地区选择器 -->
  50. <u-picker @confirm="regionConfirm" mode="region" v-model="regionShow"></u-picker>
  51. <!-- 筛选 -->
  52. <u-modal :show-cancel-button="true" cancel-text="重置" @cancel="reset" @confirm="filterConfirm" title="筛选" :mask-close-able="true" v-model="filterShow" >
  53. <view class="slot-content" style="margin: 20rpx;">
  54. <u-form label-width="150" :model="params" ref="uForm">
  55. <u-form-item label="房间名"><u-input v-model="params.name" /></u-form-item>
  56. <!-- <u-form-item :border-bottom="false" label="门牌号"><u-input v-model="params.houseNumber" /></u-form-item> -->
  57. </u-form>
  58. </view>
  59. </u-modal>
  60. <!-- 单元选择器 -->
  61. <u-picker @confirm="unitConfirm" range-key="name" :range="unitList" v-model="unitShow" mode="selector"></u-picker>
  62. <!-- 添加按钮 -->
  63. <add-btn @click.native="add"></add-btn>
  64. <!-- 通知alert -->
  65. <u-toast ref="uToast" />
  66. </view>
  67. </template>
  68. <script>
  69. import card from "./card.vue"
  70. import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
  71. let that;
  72. export default {
  73. components:{
  74. card
  75. },
  76. mixins:[MescrollMixin],
  77. data() {
  78. return {
  79. //顶部菜单栏
  80. filterMenu: ["地区","小区","楼栋","单元","筛选"],
  81. data:['','','','',''],
  82. //地区
  83. regionShow:false,
  84. areaValue:'',
  85. //底部弹出框
  86. popupShow:false,
  87. searchList:[],
  88. //筛选框
  89. filterShow:false,
  90. filterCount:0,
  91. // 列表数据
  92. params:{},
  93. keyword:'',
  94. //单元
  95. unitShow:false,
  96. unitList:[],
  97. //楼栋
  98. buildingShow:false,
  99. buildingKeyWord:'',
  100. buildingList:[],
  101. list: [],
  102. downOption: {
  103. use: true,
  104. auto: false
  105. },
  106. upOption: {
  107. page: {
  108. page: 0,
  109. size: 10
  110. },
  111. noMoreSize: 5,
  112. empty: {
  113. tip: '暂无相关数据'
  114. }
  115. },
  116. }
  117. },
  118. onLoad(){
  119. that=this
  120. this.getResidentailList({isSelect:true})
  121. },
  122. onShow() {
  123. if (this.canReset) {
  124. this.mescroll.resetUpScroll()
  125. }
  126. this.canReset=true
  127. },
  128. watch:{
  129. keyword(){
  130. let that=this
  131. //节流函数
  132. if (this.timer){
  133. clearTimeout(this.timer)//阻止setTimeout函数的执行
  134. }
  135. this.timer = setTimeout(() => {
  136. that.searchList=[]
  137. let params = {
  138. isSelect: true,
  139. regionArea: that.areaValue,
  140. name: that.keyword
  141. }
  142. this.getResidentailList(params)
  143. }, 500)
  144. },
  145. buildingKeyWord(){
  146. let that=this
  147. //节流函数
  148. if (this.timer){
  149. clearTimeout(this.timer)//阻止setTimeout函数的执行
  150. }
  151. this.timer = setTimeout(() => {
  152. that.buildingList=[]
  153. let params={
  154. residentialId:that.params.residentialId,
  155. name:that.buildingKeyWord
  156. }
  157. that.fetchBuildingList(params)
  158. }, 500)
  159. },
  160. },
  161. methods: {
  162. /**
  163. * 获取筛选的条件数
  164. */
  165. getFilterCount(){
  166. let n=0
  167. if (!this.$isEmpty(this.params.residentialId)) {
  168. //小区
  169. n++
  170. }
  171. if (!this.$isEmpty(this.params.buildingId)) {
  172. //楼栋
  173. n++
  174. }
  175. if (!this.$isEmpty(this.params.unitId)) {
  176. //单元
  177. n++
  178. }
  179. if (!this.$isEmpty(this.params.name)) {
  180. //房间名
  181. n++
  182. }
  183. this.filterCount=n
  184. },
  185. /**
  186. * 下拉回调
  187. */
  188. downCallback(){
  189. setTimeout(()=>{
  190. this.mescroll.resetUpScroll()
  191. },1500)
  192. },
  193. /**
  194. * 上拉回调
  195. * @param {Object} mescroll
  196. */
  197. upCallback(mescroll) {
  198. let params=this.params
  199. params.current=mescroll.num
  200. params.size=mescroll.size
  201. this.getFilterCount()
  202. try{
  203. this.$api.room.page(params).then(res=>{
  204. let data=res.data.records
  205. let length=data.length
  206. let total=res.data.total
  207. mescroll.endBySize(length, total);
  208. if(mescroll.num == 1) this.list = [];
  209. this.list=this.list.concat(data);
  210. })
  211. }catch(e){
  212. mescroll.endErr();
  213. }
  214. },
  215. /**
  216. * 重置
  217. */
  218. reset(){
  219. this.params={}
  220. this.data=['','','','','']
  221. this.areaValue=''
  222. this.searchList=[]
  223. this.keyword=''
  224. this.unitList=[]
  225. this.buildingKeyWord='',
  226. this.buildingList=[],
  227. this.list=[],
  228. this.mescroll.resetUpScroll()
  229. },
  230. /**
  231. * 点击选择小区,获取楼栋列表
  232. */
  233. residentailConfirm(res){
  234. //筛选标题
  235. this.params.residentialId =res.value
  236. this.data[1] = res.label
  237. this.popupShow = false
  238. //获取楼栋列表
  239. let params={
  240. residentialId:this.params.residentialId
  241. }
  242. this.fetchBuildingList(params)
  243. this.mescroll.resetUpScroll()
  244. },
  245. //点击选择楼栋,获取单元列表
  246. buildingConfirm(res){
  247. this.params.buildingId=res.id
  248. this.data[2] = res.name
  249. this.buildingShow = false
  250. let params={
  251. residentialId:this.params.residentialId,
  252. buildingId:res.id
  253. }
  254. this.getUnitByResidentialId(params)
  255. this.mescroll.resetUpScroll()
  256. },
  257. /**
  258. * 获取楼栋列表
  259. * @param {Object}
  260. */
  261. fetchBuildingList(params){
  262. this.$api.building.page(params).then(res=>{
  263. this.buildingList=res.data.records
  264. })
  265. },
  266. /**
  267. * 根据小区id获取单元列表
  268. */
  269. getUnitByResidentialId(params){
  270. this.$api.unit.page(params).then(res=>{
  271. this.unitList=res.list
  272. })
  273. },
  274. unitConfirm(index){
  275. this.data[3]=this.unitList[index].name
  276. this.params.unitId=this.unitList[index].id
  277. this.mescroll.resetUpScroll()
  278. },
  279. /**
  280. * 顶部菜单选择
  281. * @param {Object} index 菜单下标
  282. */
  283. showDown(index){
  284. if (index==0) {
  285. //地区
  286. this.regionShow=true
  287. return
  288. }
  289. if(index==1){
  290. //小区
  291. this.popupShow = true;
  292. return;
  293. }else if(index==2){
  294. //楼栋
  295. if (this.$isEmpty(this.data[1])) {
  296. this.$refs.uToast.show({
  297. title: '请先选择小区',
  298. type: 'warning',
  299. })
  300. return
  301. }
  302. this.buildingShow=true
  303. }else if (index==3) {
  304. //单元
  305. if(this.$isEmpty(this.data[2])){
  306. this.$refs.uToast.show({
  307. title: '请先选择楼栋',
  308. type: 'warning',
  309. })
  310. return
  311. }
  312. this.unitShow=true
  313. }else if (index==4) {
  314. //筛选
  315. this.filterShow=true
  316. }
  317. },
  318. /**
  319. * 确认筛选
  320. */
  321. filterConfirm(){
  322. this.mescroll.resetUpScroll()
  323. },
  324. /**
  325. * 地区确认回调
  326. * @param {Object} object
  327. */
  328. regionConfirm(object){
  329. this.data[0]= object.area.label;
  330. this.areaValue = object.area.value;
  331. let params = {
  332. isSelect: true,
  333. regionArea: this.areaValue
  334. };
  335. this.getResidentailList(params);
  336. },
  337. /**
  338. * 获取小区列表
  339. * @param {Object} params
  340. */
  341. getResidentailList(params){
  342. let list = [];
  343. this.$api.residential.page(params).then(res=>{
  344. let list=[]
  345. res.list.forEach(item=>{
  346. let obj={
  347. label:item.name,
  348. value:item.id
  349. }
  350. list.push(obj)
  351. })
  352. this.searchList = list;
  353. })
  354. },
  355. /**
  356. * 添加房间
  357. */
  358. add(){
  359. uni.navigateTo({
  360. url:"./add"
  361. })
  362. },
  363. delItem(item){
  364. this.$dialog.showModal('确定要删除此项吗?').then(res=>{
  365. this.$api,room.del({id:item.id}).then(res=>{
  366. if (res.data) {
  367. this.$showToast('删除成功')
  368. that.mescroll.resetUpScroll()
  369. }
  370. })
  371. })
  372. }
  373. }
  374. }
  375. </script>
  376. <style>
  377. </style>