residential.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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" disabled/></u-form-item>
  8. <u-form-item label="详细地址" ><u-input v-model="form.address" /></u-form-item>
  9. <u-form-item label="所属社区" :required="true">
  10. <u-input type="text" disabled v-model="form.agencyName" />
  11. </u-form-item>
  12. <u-form-item label="负责人" ><u-input v-model="form.personName" /></u-form-item>
  13. <u-form-item label="联系电话" ><u-input v-model="form.personPhone" /></u-form-item>
  14. <u-input v-model="form.agencyId" style="display: none;"/>
  15. </u-form>
  16. <view @click="submit" class="flex cu-btn bg-blue" style="margin: 60rpx 0 10rpx;padding: 40rpx;">
  17. 提交
  18. </view>
  19. </view>
  20. </u-popup>
  21. <!-- 筛选标签条 -->
  22. <view class="cu-bar bg-white flex justify-around" style="z-index: 100;width: 100%;position: fixed;top: -2rpx;">
  23. <view class="u-line-1" @click="showDown(index)" v-for="(item,index) in filterMenu" :key="index" style="width: 24%;text-align: center;height: 100%;">
  24. {{data[index]==""? item:data[index]}}
  25. <u-icon name="arrow-down-fill" size="20" style="padding-left: 10rpx;"></u-icon>
  26. </view>
  27. <view class="u-line-1" @click="filterShow=true" style="width: 26%;position: relative;text-align: center;height: 100%;">
  28. 筛选
  29. <text class="cuIcon-filter padding-left-10" ></text>
  30. <u-badge :offset="[2, 20]" size="mini" type="error" :count="filterCount"></u-badge>
  31. </view>
  32. </view>
  33. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  34. <view style="margin-top: 110rpx;">
  35. <card @edit="edit" @delItem="delItem" :list="list"></card>
  36. </view>
  37. </mescroll-body>
  38. <!-- 所属社区 -->
  39. <u-popup border-radius="60" height="60%" mode="bottom" v-model="agencypopupShow">
  40. <view class="fixed cu-bar search bg-white">
  41. <view class="search-form round">
  42. <text class="cuIcon-search"></text>
  43. <u-input style="width: 90%;" v-model="agencyKeyword" type="text" :adjust-position="false" placeholder="请输入关键字搜索" confirm-type="search"/>
  44. </view>
  45. </view>
  46. <scroll-view v-if="!$isEmpty(searchList)" style="padding-top: 110rpx;height: 100%;" :scroll-y="true" >
  47. <view @click="agencyConfirm(item)" hover-class="hoverClass" class="text-center padding-30 solid-bottom" v-for="(item,index) in searchList" :key="index">
  48. <text>{{item.name}}</text>
  49. </view>
  50. <u-divider v-if="searchList.length>=10" height="80">只显示十条数据</u-divider>
  51. </scroll-view>
  52. <u-empty v-else name="search"></u-empty>
  53. </u-popup>
  54. <!-- 地区选择器 -->
  55. <u-picker @confirm="regionConfirm" mode="region" v-model="regionShow"></u-picker>
  56. <!-- 筛选 -->
  57. <u-modal :show-cancel-button="true" cancel-text="重置" @cancel="reset" @confirm="filterConfirm" title="筛选" :mask-close-able="true" v-model="filterShow" >
  58. <view class="slot-content" style="margin: 20rpx;">
  59. <u-form label-width="150" :model="params" ref="uForm">
  60. <u-form-item label="小区名"><u-input v-model="params.name" /></u-form-item>
  61. </u-form>
  62. </view>
  63. </u-modal>
  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. import util from "../../utils/util";
  72. let that;
  73. export default {
  74. components:{
  75. card
  76. },
  77. mixins:[MescrollMixin],
  78. data() {
  79. return {
  80. //新增修改详情弹窗
  81. agencypopupShow:false,
  82. form:{},
  83. operaType:0,
  84. //顶部菜单栏
  85. filterMenu: ["地区","所属社区"],
  86. data:['','','',''],
  87. //地区
  88. regionShow:false,
  89. areaValue:'',
  90. //底部弹出框
  91. popupShow:false,
  92. searchList:[],
  93. //筛选框
  94. filterShow:false,
  95. filterCount:0,
  96. // 列表数据
  97. params:{},
  98. agencyKeyword:'',
  99. list: [],
  100. downOption: {
  101. use: true,
  102. auto: false
  103. },
  104. upOption: {
  105. page: {
  106. page: 0,
  107. size: 10
  108. },
  109. noMoreSize: 5,
  110. empty: {
  111. tip: '暂无相关数据'
  112. }
  113. },
  114. }
  115. },
  116. onLoad(){
  117. that=this
  118. this.getAgencyList()
  119. },
  120. onShow() {
  121. if (this.canReset) {
  122. this.mescroll.resetUpScroll()
  123. }
  124. this.canReset=true
  125. },
  126. watch:{
  127. agencyKeyword(){
  128. let that=this
  129. //节流函数
  130. if (this.timer){
  131. clearTimeout(this.timer)//阻止setTimeout函数的执行
  132. }
  133. this.timer = setTimeout(() => {
  134. that.searchList=[]
  135. let params = {
  136. name: that.agencyKeyword
  137. }
  138. this.getAgencyList(params)
  139. }, 500)
  140. },
  141. },
  142. methods: {
  143. /**
  144. * 获取筛选的条件数
  145. */
  146. getFilterCount(){
  147. let n=0
  148. if (!this.$isEmpty(this.params.regionArea)) {
  149. //地区
  150. n++
  151. }
  152. if (!this.$isEmpty(this.params.agencyId)) {
  153. //所属社区
  154. n++
  155. }
  156. if (!this.$isEmpty(this.params.name)) {
  157. //小区名
  158. n++
  159. }
  160. this.filterCount=n
  161. },
  162. /**
  163. * 下拉回调
  164. */
  165. downCallback(){
  166. setTimeout(()=>{
  167. this.mescroll.resetUpScroll()
  168. },1500)
  169. },
  170. /**
  171. * 上拉回调
  172. * @param {Object} mescroll
  173. */
  174. upCallback(mescroll) {
  175. let params=this.params
  176. params.current=mescroll.num
  177. params.size=mescroll.size
  178. this.getFilterCount()
  179. try{
  180. this.$api.residential.pageBycondition(params).then(res=>{
  181. let data=res.data.records
  182. let length=data.length
  183. let total=res.data.total
  184. mescroll.endBySize(length, total);
  185. if(mescroll.num == 1) this.list = [];
  186. this.list=this.list.concat(data);
  187. })
  188. }catch(e){
  189. mescroll.endErr();
  190. }
  191. },
  192. /**
  193. * 重置
  194. */
  195. reset(){
  196. this.params={}
  197. this.data=['','','','']
  198. this.areaValue=''
  199. this.searchList=[]
  200. this.agencyKeyword=''
  201. this.list=[],
  202. this.mescroll.resetUpScroll()
  203. },
  204. /**
  205. * 顶部菜单选择
  206. * @param {Object} index 菜单下标
  207. */
  208. showDown(index){
  209. if (index==0) {
  210. //地区
  211. this.regionShow=true
  212. return
  213. }
  214. if (index==1) {
  215. //所属社区
  216. this.agencypopupShow=true
  217. return
  218. }
  219. },
  220. /**
  221. * 确认筛选
  222. */
  223. filterConfirm(){
  224. this.mescroll.resetUpScroll()
  225. },
  226. /**
  227. * 地区确认回调
  228. * @param {Object} object
  229. */
  230. regionConfirm(object){
  231. console.log(object);
  232. this.data[0]= object.area.label;
  233. this.areaValue = object.area.value;
  234. this.params={
  235. regionProvince:object.province.value+"0000",
  236. regionCity:object.city.value+"00",
  237. regionArea:object.area.value
  238. }
  239. this.mescroll.resetUpScroll()
  240. },
  241. /**
  242. * 获取机构列表
  243. * @param {Object} params
  244. */
  245. getAgencyList(params){
  246. this.$api.agency.page(params).then(res=>{
  247. this.searchList=res.data.records
  248. })
  249. },
  250. /**
  251. * 点击确认选择归属
  252. */
  253. agencyConfirm(res){
  254. //筛选标题
  255. this.params.agencyId =res.id
  256. this.data[1] = res.name
  257. this.agencypopupShow = false
  258. this.mescroll.resetUpScroll()
  259. },
  260. /**
  261. * 添加小区
  262. */
  263. add(){
  264. uni.navigateTo({
  265. url:"./add"
  266. })
  267. },
  268. edit(item){
  269. this.popupShow=true
  270. this.form={
  271. id:item.id,
  272. name:item.name,
  273. address:item.address,
  274. agencyName:item.agencyName,
  275. personName:item.personName,
  276. personPhone:item.personPhone,
  277. agencyId: item.agencyId
  278. }
  279. },
  280. submit(){
  281. if (this.$isEmpty(this.form.id)) {
  282. console.log(this.form);
  283. //新增
  284. return
  285. }
  286. for (let key in this.form) {
  287. if (this.$isEmpty(this.form[key])) {
  288. delete this.form[key]
  289. }
  290. }
  291. //修改
  292. this.$api.residential.update(this.form).then(res=>{
  293. if (res.code==200) {
  294. this.$u.toast('修改成功')
  295. this.popupShow=false
  296. that.mescroll.resetUpScroll()
  297. }else{
  298. this.popupShow=false
  299. this.$u.toast('操作失败')
  300. }
  301. })
  302. },
  303. delItem(item){
  304. this.$dialog.showModal('确定要删除此项吗?').then(res=>{
  305. this.$api.residential.del({id:item.id}).then(res=>{
  306. if (res.data==true) {
  307. this.$showToast('删除成功')
  308. that.mescroll.resetUpScroll()
  309. }
  310. })
  311. })
  312. }
  313. }
  314. }
  315. </script>
  316. <style>
  317. </style>