unit.vue 10 KB

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