room.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 "./comps/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. filterMenu: ["小区","楼栋","单元","筛选"],
  82. data:['','','','',''],
  83. //地区
  84. // regionShow:false,
  85. areaValue:'',
  86. //底部弹出框
  87. popupShow:false,
  88. searchList:[],
  89. //筛选框
  90. filterShow:false,
  91. filterCount:0,
  92. // 列表数据
  93. params:{},
  94. keyword:'',
  95. //单元
  96. unitShow:false,
  97. unitList:[],
  98. //楼栋
  99. buildingShow:false,
  100. buildingKeyWord:'',
  101. buildingList:[],
  102. list: [],
  103. downOption: {
  104. use: true,
  105. auto: false
  106. },
  107. upOption: {
  108. page: {
  109. page: 0,
  110. size: 10
  111. },
  112. noMoreSize: 5,
  113. empty: {
  114. tip: '暂无相关数据'
  115. }
  116. },
  117. }
  118. },
  119. onLoad(){
  120. that=this
  121. this.getResidentailList({})
  122. },
  123. onShow() {
  124. if (this.canReset) {
  125. this.mescroll.resetUpScroll()
  126. }
  127. this.canReset=true
  128. },
  129. watch:{
  130. keyword(){
  131. let that=this
  132. //节流函数
  133. if (this.timer){
  134. clearTimeout(this.timer)//阻止setTimeout函数的执行
  135. }
  136. this.timer = setTimeout(() => {
  137. that.searchList=[]
  138. let params = {
  139. // isSelect: true,
  140. // regionArea: that.areaValue,
  141. name: that.keyword
  142. }
  143. this.getResidentailList(params)
  144. }, 500)
  145. },
  146. buildingKeyWord(){
  147. let that=this
  148. //节流函数
  149. if (this.timer){
  150. clearTimeout(this.timer)//阻止setTimeout函数的执行
  151. }
  152. this.timer = setTimeout(() => {
  153. that.buildingList=[]
  154. let params={
  155. residentialId:that.params.residentialId,
  156. name:that.buildingKeyWord
  157. }
  158. that.fetchBuildingList(params)
  159. }, 500)
  160. },
  161. },
  162. methods: {
  163. /**
  164. * 获取筛选的条件数
  165. */
  166. getFilterCount(){
  167. let n=0
  168. if (!this.$isEmpty(this.params.residentialId)) {
  169. //小区
  170. n++
  171. }
  172. if (!this.$isEmpty(this.params.buildingId)) {
  173. //楼栋
  174. n++
  175. }
  176. if (!this.$isEmpty(this.params.unitId)) {
  177. //单元
  178. n++
  179. }
  180. if (!this.$isEmpty(this.params.name)) {
  181. //房间名
  182. n++
  183. }
  184. this.filterCount=n
  185. },
  186. /**
  187. * 下拉回调
  188. */
  189. downCallback(){
  190. setTimeout(()=>{
  191. this.mescroll.resetUpScroll()
  192. },1500)
  193. },
  194. /**
  195. * 上拉回调
  196. * @param {Object} mescroll
  197. */
  198. upCallback(mescroll) {
  199. let params=this.params
  200. params.current=mescroll.num
  201. params.size=mescroll.size
  202. this.getFilterCount()
  203. try{
  204. this.$api.room.page(params).then(res=>{
  205. let data=res.data.records
  206. let length=data.length
  207. let total=res.data.total
  208. mescroll.endBySize(length, total);
  209. if(mescroll.num == 1) this.list = [];
  210. this.list=this.list.concat(data);
  211. })
  212. }catch(e){
  213. mescroll.endErr();
  214. }
  215. },
  216. /**
  217. * 重置
  218. */
  219. reset(){
  220. this.params={}
  221. this.data=['','','','','']
  222. this.areaValue=''
  223. this.searchList=[]
  224. this.keyword=''
  225. this.unitList=[]
  226. this.buildingKeyWord='',
  227. this.buildingList=[],
  228. this.list=[],
  229. this.mescroll.resetUpScroll()
  230. },
  231. /**
  232. * 点击选择小区,获取楼栋列表
  233. */
  234. residentailConfirm(res){
  235. //筛选标题
  236. this.params.residentialId =res.value
  237. this.data[0] = res.label
  238. this.popupShow = false
  239. //获取楼栋列表
  240. let params={
  241. residentialId:this.params.residentialId
  242. }
  243. this.fetchBuildingList(params)
  244. this.mescroll.resetUpScroll()
  245. },
  246. //点击选择楼栋,获取单元列表
  247. buildingConfirm(res){
  248. this.params.buildingId=res.id
  249. this.data[1] = res.name
  250. this.buildingShow = false
  251. let params={
  252. residentialId:this.params.residentialId,
  253. buildingId:res.id
  254. }
  255. this.getUnitByResidentialId(params)
  256. this.mescroll.resetUpScroll()
  257. },
  258. /**
  259. * 获取楼栋列表
  260. * @param {Object}
  261. */
  262. fetchBuildingList(params){
  263. this.$api.building.page(params).then(res=>{
  264. this.buildingList=res.data.records
  265. })
  266. },
  267. /**
  268. * 根据小区id获取单元列表
  269. */
  270. getUnitByResidentialId(params){
  271. this.$api.unit.page(params).then(res=>{
  272. this.unitList=res.data.records
  273. })
  274. },
  275. unitConfirm(index){
  276. this.data[2]=this.unitList[index].name
  277. this.params.unitId=this.unitList[index].id
  278. this.mescroll.resetUpScroll()
  279. },
  280. /**
  281. * 顶部菜单选择
  282. * @param {Object} index 菜单下标
  283. */
  284. showDown(index){
  285. // if (index==0) {
  286. // //地区
  287. // this.regionShow=true
  288. // return
  289. // }
  290. if(index==0){
  291. //小区
  292. this.popupShow = true;
  293. return;
  294. }else if(index==1){
  295. //楼栋
  296. if (this.$isEmpty(this.data[0])) {
  297. this.$refs.uToast.show({
  298. title: '请先选择小区',
  299. type: 'warning',
  300. })
  301. return
  302. }
  303. this.buildingShow=true
  304. }else if (index==2) {
  305. //单元
  306. if(this.$isEmpty(this.data[1])){
  307. this.$refs.uToast.show({
  308. title: '请先选择楼栋',
  309. type: 'warning',
  310. })
  311. return
  312. }
  313. this.unitShow=true
  314. }else if (index==3) {
  315. //筛选
  316. this.filterShow=true
  317. }
  318. },
  319. /**
  320. * 确认筛选
  321. */
  322. filterConfirm(){
  323. this.mescroll.resetUpScroll()
  324. },
  325. /**
  326. * 地区确认回调
  327. * @param {Object} object
  328. */
  329. // regionConfirm(object){
  330. // this.data[0]= object.area.label;
  331. // this.areaValue = object.area.value;
  332. // let params = {
  333. // // isSelect: true,
  334. // regionArea: this.areaValue
  335. // };
  336. // this.getResidentailList(params);
  337. // },
  338. /**
  339. * 获取小区列表
  340. * @param {Object} params
  341. */
  342. getResidentailList(params){
  343. let list = [];
  344. this.$api.residential.page(params).then(res=>{
  345. let list=[]
  346. res.data.records.forEach(item=>{
  347. let obj={
  348. label:item.name,
  349. value:item.id
  350. }
  351. list.push(obj)
  352. })
  353. this.searchList = list;
  354. })
  355. },
  356. /**
  357. * 添加房间
  358. */
  359. add(){
  360. uni.navigateTo({
  361. url:"./add"
  362. })
  363. },
  364. delItem(item){
  365. this.$dialog.showModal('确定要删除此项吗?').then(res=>{
  366. this.$api,room.del({id:item.id}).then(res=>{
  367. if (res.data) {
  368. this.$showToast('删除成功')
  369. that.mescroll.resetUpScroll()
  370. }
  371. })
  372. })
  373. }
  374. }
  375. }
  376. </script>
  377. <style>
  378. </style>