add.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view class="" >
  3. <u-toast ref="uToast"/>
  4. <view class="bg-white" style="padding: 10rpx 30rpx;margin: 20rpx;border-radius: 12rpx;">
  5. <u-form :label-style="labelStyle" label-width="150" :model="form" ref="uForm">
  6. <u-form-item label="房间名称" :required="true"><u-input v-model="form.name" placeholder="请输入房间名称"/></u-form-item>
  7. <u-form-item v-if="!$isEmpty(form.id)" label="门牌号" :required="true"><u-input v-model="form.houseNumber" placeholder="请输入门牌号"/></u-form-item>
  8. <u-form-item label="所属小区" :required="true">
  9. <u-input v-if="$isEmpty(form.id)" type="select" :select-open="residentialShow" v-model="residentialName" placeholder="请选择小区" @click="residentialShow=true"></u-input>
  10. <u-input v-else disabled v-model="form.residentialName" ></u-input>
  11. </u-form-item>
  12. <u-form-item label="所属楼栋" :required="true">
  13. <!-- 新增 -->
  14. <u-input v-if="$isEmpty(form.id)" type="select" :select-open="buildingShow" v-model="buildingName" placeholder="请选择小区" @click="showBuilding"></u-input>
  15. <!-- 修改 -->
  16. <u-input v-else disabled v-model="form.buildingName" ></u-input>
  17. </u-form-item>
  18. <u-form-item label="所属单元" :required="true">
  19. <u-input v-if="$isEmpty(form.id)" v-model="unitName" type="select" :select-open="unitShow" placeholder="请选择单元" @click="showUnit"></u-input>
  20. <u-input v-else v-model="form.unitName" disabled ></u-input>
  21. </u-form-item>
  22. <u-form-item label="面积">
  23. <u-input v-model="form.area" type="number" placeholder="请填写房间面积"></u-input>
  24. </u-form-item>
  25. <u-form-item label="户型">
  26. <u-input v-model="form.houseType" placeholder="请填写房间户型"></u-input>
  27. </u-form-item>
  28. <u-form-item label="楼层">
  29. <u-input v-model="form.floorName" placeholder="请填写房间楼层"></u-input>
  30. </u-form-item>
  31. <u-form-item label="装修">
  32. <u-input v-model="form.ornament" placeholder="请填写房间装修"></u-input>
  33. </u-form-item>
  34. <u-form-item label="朝向">
  35. <u-input v-model="form.orientation" placeholder="请填写房间朝向"></u-input>
  36. </u-form-item>
  37. <u-form-item label="序号">
  38. <u-number-box :min="1" :max="100" solt="right" v-model="form.serial" ></u-number-box>
  39. </u-form-item>
  40. <u-form-item label="备注" label-position="top">
  41. <u-input type="textarea" height="300" maxlength="300" v-model="form.remark" placeholder="请输入300字以内的备注介绍"></u-input>
  42. </u-form-item>
  43. </u-form>
  44. </view>
  45. <!-- 小区 -->
  46. <u-popup border-radius="60" height="60%" mode="bottom" v-model="residentialShow">
  47. <view class="fixed cu-bar search bg-white">
  48. <view class="search-form round">
  49. <text class="cuIcon-search"></text>
  50. <u-input style="width: 90%;" v-model="residentialKeyword" type="text" :adjust-position="false" placeholder="请输入关键字搜索" confirm-type="search"/>
  51. </view>
  52. </view>
  53. <scroll-view v-if="!$isEmpty(residentialList)" style="padding-top: 110rpx;height: 100%;" :scroll-y="true" >
  54. <view @click="residentialConfirm(item)" hover-class="hoverClass" class="text-center padding-30 solid-bottom" v-for="(item,index) in residentialList" :key="index">
  55. <text>{{item.name}}</text>
  56. </view>
  57. <u-divider v-if="residentialList.length>=10" height="80">只显示十条数据</u-divider>
  58. </scroll-view>
  59. <u-empty v-else name="search"></u-empty>
  60. </u-popup>
  61. <!-- 楼栋 -->
  62. <u-popup border-radius="60" height="60%" mode="bottom" v-model="buildingShow">
  63. <view class="fixed cu-bar search bg-white">
  64. <view class="search-form round">
  65. <text class="cuIcon-search"></text>
  66. <u-input style="width: 90%;" v-model="buildingKeyWord" type="text" :adjust-position="false" placeholder="请输入关键字搜索" confirm-type="search"/>
  67. </view>
  68. </view>
  69. <scroll-view v-if="!$isEmpty(buildingList)" style="padding-top: 110rpx;height: 100%;" :scroll-y="true" >
  70. <view @click="buildingConfirm(item)" hover-class="hoverClass" class="text-center padding-30 solid-bottom" v-for="(item,index) in buildingList" :key="index">
  71. <text>{{item.name}}</text>
  72. </view>
  73. <u-divider v-if="buildingList.length>=10" height="80">只显示十条数据</u-divider>
  74. </scroll-view>
  75. <u-empty v-else name="search"></u-empty>
  76. </u-popup>
  77. <u-picker @confirm="unitConfirm" range-key="name" :range="unitList" v-model="unitShow" mode="selector"></u-picker>
  78. <view @click="confirm" class="bottom-bar" >
  79. <view class="cu-btn bg-blue radius" style="width: 70%;height: 84rpx;">
  80. 提交
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <script>
  86. export default {
  87. name: '',
  88. data() {
  89. return {
  90. labelStyle:{
  91. "fontWeight":"600"
  92. },
  93. form:{
  94. name:'',
  95. residentialId:'',
  96. unitId:'',
  97. houseType:'',
  98. floor:'',
  99. orientation:'',
  100. serial:1,
  101. remark:''
  102. },
  103. //小区
  104. residentialName:'',
  105. residentialShow:false,
  106. residentialKeyword:'',
  107. residentialList:[],
  108. //楼栋
  109. buildingName:'',
  110. buildingShow:false,
  111. buildingKeyWord:'',
  112. buildingList:'',
  113. //单元
  114. unitName:'',
  115. unitList:[],
  116. unitShow:false
  117. };
  118. },
  119. onLoad(options) {
  120. //加载小区数据
  121. this.fetchResidentialList()
  122. if (!this.$isEmpty(options.id)) {
  123. this.form.id=options.id
  124. this.fetchDataDetail()
  125. uni.setNavigationBarTitle({
  126. title:"修改房间信息"
  127. })
  128. }
  129. },
  130. watch:{
  131. //小区
  132. residentialKeyword(){
  133. let that=this
  134. if (this.timer){
  135. clearTimeout(this.timer)
  136. }
  137. this.timer = setTimeout(() => {
  138. that.residentialList=[]
  139. that.getResidentailList()
  140. }, 500)
  141. },
  142. //楼栋
  143. buildingKeyWord(){
  144. let that=this
  145. if (this.timer){
  146. clearTimeout(this.timer)
  147. }
  148. this.timer = setTimeout(() => {
  149. that.buildingList=[]
  150. let params={
  151. residentialId:that.form.residentialId,
  152. name:that.buildingKeyWord
  153. }
  154. that.fetchBuildingList(params)
  155. }, 500)
  156. },
  157. },
  158. methods:{
  159. fetchDataDetail(){
  160. this.$api.room.pageBycondition({id:this.form.id}).then(res=>{
  161. this.form=res.list[0]
  162. })
  163. },
  164. //修改房间时,加载房间的数据
  165. /**
  166. * 获取小区数据列表
  167. */
  168. fetchResidentialList(){
  169. let params={
  170. isSelect: true,
  171. name:this.residentialKeyword
  172. }
  173. this.$api.residential.page(params).then(res=>{
  174. this.residentialList = res.list
  175. })
  176. },
  177. //点击选择小区时
  178. residentialConfirm(item){
  179. //赋值给提交的数据
  180. this.form.residentialId=item.id
  181. //赋值给回显的名称
  182. this.residentialName=item.name
  183. //加载楼栋信息
  184. this.buildingList=[]
  185. let params={
  186. residentialId:item.id
  187. }
  188. this.fetchBuildingList(params)
  189. this.residentialShow=false
  190. },
  191. showBuilding(){
  192. if (this.$isEmpty(this.residentialName)) {
  193. this.$showToast('请先选择小区','warning')
  194. return
  195. }
  196. this.buildingShow=true
  197. },
  198. showUnit(){
  199. if (this.$isEmpty(this.buildingName)) {
  200. this.$showToast('请先选择楼栋','warning')
  201. return
  202. }
  203. this.unitShow=true
  204. },
  205. /**
  206. * 获取楼栋列表
  207. * @param {Object}
  208. */
  209. fetchBuildingList(params){
  210. this.$api.building.page(params).then(res=>{
  211. this.buildingList=res.data.records
  212. })
  213. },
  214. /**
  215. * 选择楼栋
  216. */
  217. buildingConfirm(item){
  218. // 赋值给提交的数据
  219. this.form.buildingId=item.id
  220. //数据回显
  221. this.buildingName=item.name
  222. //加载单元列表
  223. this.fetchUnitList()
  224. this.buildingShow=false
  225. },
  226. /**
  227. * 获取单元列表
  228. */
  229. fetchUnitList(){
  230. let params={
  231. buildingId:this.form.buildingId,
  232. residentialId:this.form.residentialId
  233. }
  234. this.$api.unit.page(params).then(res=>{
  235. this.unitList = res.list
  236. })
  237. },
  238. /**
  239. * 点击选择单元
  240. * @param {Object}
  241. */
  242. unitConfirm(e){
  243. console.log(e);
  244. //赋值给提交的数据
  245. this.form.unitId=this.unitList[e[0]].id
  246. //赋值给回显的名称
  247. this.unitName=this.unitList[e[0]].name
  248. this.unitShow=false
  249. },
  250. confirm(){
  251. if (this.$isEmpty(this.form.name)) {
  252. this.$u.toast('请输入房间名称')
  253. return
  254. }
  255. if (this.$isEmpty(this.form.residentialId)) {
  256. this.$u.toast("请选择小区")
  257. return
  258. }
  259. if (this.$isEmpty(this.form.buildingId)) {
  260. this.$u.toast("请选择楼栋")
  261. return
  262. }
  263. if (this.$isEmpty(this.form.unitId)) {
  264. this.$u.toast('请选择单元')
  265. return
  266. }
  267. console.log(this.form);
  268. if (this.$isEmpty(this.form.id)) {
  269. this.$api.room.add(this.form).then(res=>{
  270. if (res.data) {
  271. this.$dialog.showModal('操作成功',false).then(res=>{
  272. uni.navigateBack()
  273. })
  274. }else{
  275. this.$u.toast('操作失败')
  276. }
  277. })
  278. //新增
  279. }else{
  280. let {oldId,orgPosition,...params}=this.form
  281. //修改
  282. this.$api.room.update(params).then(res=>{
  283. if (res.data==true) {
  284. this.$dialog.showModal('操作成功',false).then(res=>{
  285. uni.navigateBack()
  286. })
  287. }else{
  288. this.$u.toast('操作失败')
  289. }
  290. })
  291. }
  292. }
  293. }
  294. };
  295. </script>
  296. <style lang="scss" scoped>
  297. page{
  298. background-color: #FFFFFF;
  299. }
  300. </style>