add.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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">
  7. <u-input v-model="form.name" placeholder="请输入小区名称"/>
  8. </u-form-item>
  9. <u-form-item label="归属" :required="true">
  10. <u-input type="select" :select-open="agencyShow" v-model="form.agencyName" placeholder="请选择归属" @click="agencyShow=true"></u-input>
  11. </u-form-item>
  12. <!-- <u-form-item v-if="!$isEmpty(form.id)" label="详细地址" :required="true">
  13. <u-input v-model="form.address" type="number" placeholder="详细地址"></u-input>
  14. </u-form-item> -->
  15. <u-form-item v-if="!$isEmpty(form.id)" label="物业" :required="true">
  16. <u-input v-model="form.estatePidName" placeholder="请输入物业名称"/>
  17. </u-form-item>
  18. <u-form-item label="物业电话" required="true">
  19. <u-input v-model="form.estatePidPhone" placeholder="请填写物业电话"></u-input>
  20. </u-form-item>
  21. <u-form-item label="负责人姓名">
  22. <u-input v-model="form.personName" placeholder="请填写负责人姓名"></u-input>
  23. </u-form-item>
  24. <u-form-item label="负责人电话">
  25. <u-input v-model="form.personTel" placeholder="请填写负责人电话"></u-input>
  26. </u-form-item>
  27. <u-form-item label="小区图片" :border-bottom="false"></u-form-item>
  28. <u-form-item>
  29. <g-upload ref='gUpload' :mode="imgList" @chooseFile='chooseFile' @imgDelete='imgDelete' :columnNum="columnNum"></g-upload>
  30. </u-form-item>
  31. <u-form-item label="选择地址">
  32. <input v-model="form.address" placeholder="请选择地址"/>
  33. </u-form-item>
  34. <view>
  35. <map style="width: 100%; height: 300px;" :latitude="form.latitude" :longitude="form.longitude" @click="getpoint">
  36. </map>
  37. </view>
  38. <u-form-item label="备注" label-position="top">
  39. <u-input type="textarea" height="300" maxlength="300" v-model="form.remark" placeholder="请输入300字以内的备注介绍"></u-input>
  40. </u-form-item>
  41. </u-form>
  42. </view>
  43. <!-- 归属筛选 -->
  44. <u-popup border-radius="60" height="60%" mode="bottom" v-model="agencyShow">
  45. <view class="fixed cu-bar search bg-white">
  46. <view class="search-form round">
  47. <text class="cuIcon-search"></text>
  48. <u-input style="width: 90%;" v-model="agencyKeyword" type="text" :adjust-position="false" placeholder="请输入关键字搜索" confirm-type="search"/>
  49. </view>
  50. </view>
  51. <scroll-view v-if="!$isEmpty(agencyList)" style="padding-top: 110rpx;height: 100%;" :scroll-y="true" >
  52. <view @click="agencyConfirm(item)" hover-class="hoverClass" class="text-center padding-30 solid-bottom" v-for="(item,index) in agencyList" :key="index">
  53. <text>{{item.label}}</text>
  54. </view>
  55. <u-divider v-if="agencyList.length>=10" height="80">只显示十条数据</u-divider>
  56. </scroll-view>
  57. <u-empty v-else name="search"></u-empty>
  58. </u-popup>
  59. <view @click="confirm" class="bottom-bar" >
  60. <view class="cu-btn bg-blue radius" style="width: 70%;height: 84rpx;">
  61. 提交
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import gUpload from "@/components/g-upload/g-upload.vue"
  68. export default {
  69. components:{gUpload},
  70. name: '',
  71. data() {
  72. return {
  73. //图片上传
  74. title: '上传图片',
  75. columnNum: 4,
  76. imgList: [],
  77. labelStyle:{
  78. "fontWeight":"600"
  79. },
  80. form:{
  81. name:'',
  82. agencyName:'',
  83. agencyId:'',
  84. houseType:'',
  85. address:'',
  86. orientation:'',
  87. estatePidName:'',
  88. estatePidPhone:'',
  89. latitude: 38.473929061,
  90. longitude: 106.288550642,
  91. remark:'',
  92. pic:[],
  93. },
  94. id:0, // 使用 marker点击事件 需要填写id
  95. title: 'map',
  96. covers: [{
  97. latitude: 39.909,
  98. longitude: 116.39742,
  99. iconPath: '../../static/tarbar/ditubiaoji.png'
  100. }],
  101. //归属
  102. agencyName:'',
  103. agencyShow:false,
  104. residentialKeyword:'',
  105. agencyList:[],
  106. };
  107. },
  108. onLoad(options) {
  109. //加载小区数据
  110. console.log(555,options)
  111. this.fetchagencyList()
  112. if (!this.$isEmpty(options.item)) {
  113. this.form=JSON.parse(options.item)
  114. // this.fetchDataDetail()
  115. uni.setNavigationBarTitle({
  116. title:"修改小区信息"
  117. })
  118. }
  119. },
  120. watch:{
  121. //归属
  122. agencyKeyword(){
  123. let that=this
  124. if (this.timer){
  125. clearTimeout(this.timer)
  126. }
  127. this.timer = setTimeout(() => {
  128. that.agencyList=[]
  129. let params = {
  130. // isSelect: true,
  131. regionArea: that.areaValue,
  132. agencyName: that.agencyKeyword
  133. }
  134. that.fetchagencyList(params)
  135. }, 500)
  136. },
  137. },
  138. methods:{
  139. /**
  140. * 获取地图位置
  141. */
  142. getpoint(){
  143. let that = this
  144. uni.chooseLocation({
  145. success: function (res) {
  146. console.log(res)
  147. console.log(333,that.form)
  148. that.form.address = res.address+res.name
  149. that.form.latitude = res.latitude
  150. that.form.longitude = res.longitude
  151. }
  152. })
  153. },
  154. /**
  155. * 获取上个界面携带小区信息
  156. */
  157. fetchDataDetail(){
  158. this.$api.residential.page({id:this.form.id}).then(res=>{
  159. console.log(res.list[0])
  160. this.form=res.list[0]
  161. })
  162. },
  163. /**
  164. * 上传图片方法
  165. */
  166. //点击上传控件上传
  167. uploadImg() {
  168. this.$refs.gUpload.uploadImg()
  169. },
  170. /*
  171. 上传后返回的值:
  172. list:上传后图片数组
  173. v:返回当前上传图片的临时路径
  174. */
  175. chooseFile(list, v) {
  176. console.log("上传图片_list:", list)
  177. console.log("上传图片_v:", v);
  178. this.uploadFileToServe(v)
  179. },
  180. /*
  181. 删除图片:
  182. list:删除返回删除后剩余的图片数组
  183. eq:返回删除的数组
  184. */
  185. imgDelete(list, eq) {
  186. console.log("删除图片_list:", list)
  187. console.log("删除图片_eq:", eq)
  188. },
  189. /*
  190. 执行上传服务:
  191. urlList:要上传的图片:数组类型
  192. */
  193. uploadFileToServe(urlList) {
  194. if (!urlList || urlList.length <= 0) {
  195. return
  196. };
  197. for (let i = 0; i < urlList.length; i++) {
  198. uni.uploadFile({
  199. url: 'https://www.example.com/upload', //上传接口
  200. filePath: urlList[i],
  201. name: 'file',
  202. formData: {
  203. 'user': 'test'
  204. },
  205. success: (uploadFileRes) => {
  206. console.log(uploadFileRes.data);
  207. }
  208. });
  209. }
  210. },
  211. /**
  212. * 获取小区数据列表
  213. */
  214. // fetchagencyList(){
  215. // let params={
  216. // isSelect: true,
  217. // name:this.residentialKeyword
  218. // }
  219. // this.$api.residential.page(params).then(res=>{
  220. // this.agencyList = res.list
  221. // })
  222. // },
  223. //点击选择归属时
  224. agencyConfirm(item){
  225. //赋值给提交的数据
  226. this.form.agencyId=item.value
  227. //赋值给回显的名称
  228. this.form.agencyName=item.label
  229. this.agencyShow=false
  230. },
  231. /**
  232. * 获取机构列表
  233. * @param {Object} params
  234. */
  235. fetchagencyList(params){
  236. let list = [];
  237. this.$api.permissions.orgList(params).then(res=>{
  238. console.log(res)
  239. let list = [];
  240. for(let item of res.data.records){
  241. let element = {
  242. label: item.parentName,
  243. value: item.id
  244. }
  245. list.splice(list.length,0,element);
  246. // list.push(obj);
  247. }
  248. this.agencyList = list;
  249. console.log(444,this.agencyList)
  250. // this.mescroll.resetUpScroll()
  251. })
  252. },
  253. confirm(){
  254. if (this.$isEmpty(this.form.name)) {
  255. this.$u.toast('请输入小区名称')
  256. return
  257. }
  258. if (this.$isEmpty(this.form.agencyId)) {
  259. this.$u.toast("请选择归属")
  260. return
  261. }
  262. if (this.$isEmpty(this.form.estatePidName)) {
  263. this.$u.toast("请输入物业")
  264. return
  265. }
  266. if (this.$isEmpty(this.form.estatePidPhone)) {
  267. this.$u.toast('请输入物业电话')
  268. return
  269. }
  270. console.log(this.form);
  271. if (this.$isEmpty(this.form.id)) {
  272. return
  273. this.$api.room.add(this.form).then(res=>{
  274. if (res.data) {
  275. this.$dialog.showModal('操作成功',false).then(res=>{
  276. uni.navigateBack()
  277. })
  278. }else{
  279. this.$u.toast('操作失败')
  280. }
  281. })
  282. //新增
  283. }else{
  284. let {oldId,orgPosition,...params}=this.form
  285. //修改
  286. this.$api.room.update(params).then(res=>{
  287. if (res.data==true) {
  288. this.$dialog.showModal('操作成功',false).then(res=>{
  289. uni.navigateBack()
  290. })
  291. }else{
  292. this.$u.toast('操作失败')
  293. }
  294. })
  295. }
  296. }
  297. }
  298. };
  299. </script>
  300. <style lang="scss" scoped>
  301. page{
  302. background-color: #FFFFFF;
  303. }
  304. </style>