building.vue 9.3 KB

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