AddOrEdit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="main">
  3. <div class="blockName">{{ !isAdd ? '编辑' : '新增' }}社区(<span class="show-required-icon-star"></span>为必填项)</div>
  4. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="formContent">
  5. <div class="formContent-item">
  6. <div class="formContent-item_title">基础信息</div>
  7. <el-form-item label="社区名称" prop="communityName">
  8. <el-input v-model="ruleForm.communityName"></el-input>
  9. </el-form-item>
  10. <el-form-item label="所在地区" prop="regionId">
  11. <el-cascader
  12. v-model="regionId"
  13. :options="locationList"
  14. class="width100"
  15. placeholder="请选择区域"
  16. :props="{ label: 'name', value: 'code' }"
  17. @change="productChange($event)"
  18. ></el-cascader>
  19. </el-form-item>
  20. <el-form-item label="所属公司" prop="companyOrgId">
  21. <select-tree
  22. class="new-select-tree"
  23. selectTreeTitle="请选择公司"
  24. placeholder="请选择公司"
  25. :options="companyArray"
  26. :props="defaultProps"
  27. v-model="ruleForm.companyOrgId"
  28. />
  29. </el-form-item>
  30. <!-- <el-form-item label="所属部门">
  31. <select-tree
  32. class="new-select-tree"
  33. placeholder="请选择部门"
  34. :options="departmentArray"
  35. selectTreeTitle="请选择部门"
  36. :props="defaultProps"
  37. v-model="ruleForm.deptOrgId"
  38. />
  39. </el-form-item> -->
  40. <el-form-item label="详细地址" prop="address">
  41. <el-input v-model="ruleForm.address">
  42. <i slot="suffix" class="zoniot_font zoniot-icon-dizhi" @click="addressQueryClick"></i>
  43. </el-input>
  44. </el-form-item>
  45. <el-form-item label="占地面积(㎡)">
  46. <el-input v-model="ruleForm.coveredArea"></el-input>
  47. </el-form-item>
  48. <el-form-item label="建筑面积(㎡)">
  49. <el-input v-model="ruleForm.buildingArea"></el-input>
  50. </el-form-item>
  51. <el-form-item label="商业面积(㎡)">
  52. <el-input v-model="ruleForm.commercialArea"></el-input>
  53. </el-form-item>
  54. <el-form-item label="住宅面积(㎡)">
  55. <el-input v-model="ruleForm.dwellingArea"></el-input>
  56. </el-form-item>
  57. <el-form-item label="绿化面积(㎡)">
  58. <el-input v-model="ruleForm.greenArea"></el-input>
  59. </el-form-item>
  60. <el-form-item label="车位面积(㎡)">
  61. <el-input v-model="ruleForm.parkingArea"></el-input>
  62. </el-form-item>
  63. <el-form-item label="社区图片">
  64. <div class="clickUpload">
  65. <div class="clickUpText">
  66. <img class="dataImg" v-if="!!ruleForm.pictureUrl" :src="ruleForm.pictureUrl" />
  67. <template v-else>
  68. <div class="addImg"><i class="el-icon-plus"></i></div>
  69. </template>
  70. </div>
  71. <el-upload
  72. v-if="!islooks"
  73. :headers="token"
  74. ref="uploaduserlogo"
  75. limit="1"
  76. action="/sc-community/upload/uploadFile"
  77. :on-success="uploadsuccess"
  78. :before-upload="beforeAvatarUpload"
  79. :auto-upload="true"
  80. name="file"
  81. >
  82. </el-upload>
  83. </div>
  84. </el-form-item>
  85. </div>
  86. <div class="formContent-item">
  87. <div class="formContent-item_title">负责人</div>
  88. <el-form-item label="负责人姓名" prop="contactPerson">
  89. <el-input v-model="ruleForm.contactPerson"></el-input>
  90. </el-form-item>
  91. <el-form-item label="手机号码" prop="phone">
  92. <el-input v-model="ruleForm.phone"></el-input>
  93. </el-form-item>
  94. <el-form-item label="固定电话">
  95. <el-input v-model="ruleForm.telephone"></el-input>
  96. </el-form-item>
  97. <el-form-item label="备注信息">
  98. <el-input type="textarea" :rows="4" v-model="ruleForm.remarks" maxlength="300" show-word-limit> </el-input>
  99. </el-form-item>
  100. </div>
  101. </el-form>
  102. <div style="text-align: right">
  103. <el-button @click="close">取消</el-button>
  104. <el-button type="primary" @click="addEdit">保存</el-button>
  105. </div>
  106. <!--地图详情地址弹出框-->
  107. <el-dialog title="选择地址" :append-to-body="true" :visible.sync="mapPopUpStatus" width="600px">
  108. <map-popup @getDot="getDot"></map-popup>
  109. </el-dialog>
  110. </div>
  111. </template>
  112. <script>
  113. import MapPopup from '@/components/mapPopup/index.vue';
  114. export default {
  115. props: {
  116. params: {
  117. type: Object
  118. },
  119. isAdd: {
  120. type: Boolean,
  121. default: true
  122. }
  123. },
  124. data() {
  125. return {
  126. regionId: '',
  127. locationList: [], //地区列表
  128. ruleForm: {
  129. address: '', //详细地址
  130. buildingArea: '', //建筑面积
  131. cityId: '', //城市id
  132. commercialArea: '', //商业面积
  133. communityName: '', //社区名称
  134. companyOrgId: '', //所属公司
  135. contactPerson: '', //负责人
  136. coveredArea: '', //占地面积
  137. // deptOrgId: '', //所属部门
  138. dwellingArea: '', //住宅面积
  139. greenArea: '', //绿化面积
  140. id: '',
  141. latitude: '', //纬度
  142. longitude: '', //经度
  143. parkingArea: '', //车位面积
  144. phone: '', //负责人手机号
  145. pictureUrl: '', //社区图片
  146. provinceId: '',
  147. regionId: '', //所在地区
  148. remarks: '', //备注
  149. telephone: ''
  150. },
  151. token: {
  152. [localStorage.getItem('SC_token') && 'Authorization']: 'Bearer ' + localStorage.getItem('SC_token')
  153. },
  154. defaultProps: {
  155. value: 'id', // 唯一标识
  156. label: 'orgName', // 标签显示
  157. children: 'orgs' // 子级
  158. },
  159. rules: {
  160. communityName: [this.$valid.inputRequired('社区名称')],
  161. address: [this.$valid.selectRequired('地址')],
  162. regionId: [this.$valid.selectRequired('地区')],
  163. companyOrgId: [this.$valid.selectRequired('公司')],
  164. phone: [
  165. this.$valid.inputRequired('手机号'),
  166. this.$valid.pattern(
  167. /^((0\d{2,3}-\d{7,8})|((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|147)\d{8})$/
  168. )
  169. ],
  170. contactPerson: [this.$valid.inputRequired('负责人姓名')]
  171. },
  172. mapPopUpStatus: false //地图弹出框
  173. };
  174. },
  175. components: {
  176. MapPopup
  177. },
  178. computed: {
  179. companyArray() {
  180. return this.$store.getters['getCompanyArray'];
  181. },
  182. departmentArray() {
  183. return this.$store.getters['getDepartmentArray'];
  184. }
  185. },
  186. methods: {
  187. productChange(va) {
  188. this.ruleForm.provinceId = va[0];
  189. this.ruleForm.cityId = va[1];
  190. this.ruleForm.regionId = _.last(va);
  191. },
  192. // productChange2(va) {
  193. // this.ruleForm.companyOrgId = _.last(va);
  194. // },
  195. // productChange3(va) {
  196. // this.ruleForm.deptOrgId = _.last(va);
  197. // },
  198. getDot(item) {
  199. this.ruleForm.address = item.cityname + item.adname + item.address;
  200. this.ruleForm.latitude = item.location.lat;
  201. this.ruleForm.longitude = item.location.lng;
  202. this.mapPopUpStatus = !this.mapPopUpStatus;
  203. },
  204. //保存
  205. addEdit() {
  206. this.$refs.ruleForm.validate((valid) => {
  207. console.log(this.ruleForm);
  208. if (valid) {
  209. let url = '/sc-community/assets/community/add';
  210. let params = this.ruleForm;
  211. if (!this.isAdd) {
  212. url = '/sc-community/assets/community/update';
  213. }
  214. this.$http
  215. .post(url, params)
  216. .then(({ status, msg }) => {
  217. if (status == 0) {
  218. this.$message.success(msg);
  219. this.close();
  220. } else {
  221. this.$message.error(msg);
  222. }
  223. })
  224. .catch(() => {});
  225. }
  226. });
  227. },
  228. //所属地区
  229. regionalQuery() {
  230. this.$http.postForm('/sc-user-center/area/selectAll', { id: 123 }).then(({ status, data, msg }) => {
  231. if (status === 0 && data) {
  232. this.locationList = data;
  233. }
  234. });
  235. },
  236. uploadsuccess(response, file, fileList) {
  237. this.$refs.uploaduserlogo.clearFiles();
  238. if (0 === response.status) {
  239. this.ruleForm.pictureUrl = response.data;
  240. }
  241. },
  242. beforeAvatarUpload(file) {
  243. const isJPG = file.type === 'image/jpeg';
  244. const isLt2M = file.size / 1024 / 1024 < 2;
  245. // if (!isJPG) {
  246. // this.$message.error('上传头像图片只能是 JPG 格式!');
  247. // }
  248. if (!isLt2M) {
  249. this.$message.error('上传头像图片大小不能超过 2MB!');
  250. }
  251. return isJPG && isLt2M;
  252. },
  253. addressQueryClick() {
  254. this.mapPopUpStatus = true;
  255. },
  256. getDetails(id) {
  257. let url = '/sc-community/assets/community/find/' + id;
  258. this.$http
  259. .get(url)
  260. .then(({ data, status, msg }) => {
  261. if (0 === status) {
  262. this.ruleForm = data;
  263. this.regionId = [data.provinceId, data.cityId, data.regionId];
  264. // this.companyOrgId = [null, null, data.companyOrgId];
  265. // this.deptOrgId = [null, null, data.deptOrgId];
  266. } else {
  267. this.$message.error(msg);
  268. }
  269. })
  270. .catch(() => {});
  271. },
  272. close() {
  273. this.$emit('clerOwnerStatus');
  274. }
  275. },
  276. created() {
  277. this.regionalQuery();
  278. if (!!this.params.id) {
  279. this.getDetails(this.params.id);
  280. }
  281. }
  282. };
  283. </script>
  284. <style lang='scss' scoped>
  285. @import '@assets/css/public-style.scss';
  286. .main {
  287. padding: 20px;
  288. background: white;
  289. .blockName {
  290. padding-bottom: 20px;
  291. margin-bottom: 20px;
  292. border-bottom: 1px solid #e0e1e3;
  293. }
  294. }
  295. /deep/ .avatar-uploader .el-upload {
  296. border: 1px dashed #d9d9d9;
  297. width: 200px;
  298. border-radius: 6px;
  299. cursor: pointer;
  300. position: relative;
  301. overflow: hidden;
  302. }
  303. .show-required-icon-star {
  304. &:before {
  305. content: '*';
  306. color: #f56c6c;
  307. }
  308. }
  309. .formContent {
  310. display: flex;
  311. justify-content: space-between;
  312. .formContent-item {
  313. width: 49%;
  314. }
  315. }
  316. // .formContent-item_title {
  317. // font-size: 14px;
  318. // position: relative;
  319. // margin-left: 14px;
  320. // margin-bottom: 20px;
  321. // &::before {
  322. // position: absolute;
  323. // left: -14px;
  324. // top: 4px;
  325. // width: 4px;
  326. // height: 12px;
  327. // border-radius: 2px;
  328. // display: block;
  329. // background: $mainBgColor;
  330. // content: ' ';
  331. // }
  332. // }
  333. .clickUpload {
  334. width: 72px;
  335. height: 72px;
  336. border-radius: 4px;
  337. border: 1px solid #e0e1e3;
  338. position: relative;
  339. z-index: 1000;
  340. text-align: center;
  341. overflow: hidden;
  342. font-size: 12px;
  343. cursor: pointer;
  344. color: #d8d8d8;
  345. .mini-upload {
  346. position: absolute;
  347. z-index: 0;
  348. }
  349. }
  350. .clickUpText {
  351. height: 100%;
  352. width: 100%;
  353. pointer-events: none;
  354. position: absolute;
  355. background: white;
  356. z-index: 1;
  357. img.dataImg {
  358. width: 100%;
  359. height: 100%;
  360. object-fit: cover;
  361. }
  362. .addImg {
  363. line-height: 72px;
  364. & > i {
  365. font-size: 30px;
  366. }
  367. }
  368. }
  369. </style>