addPoint.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div>
  3. <zz-form :cols="formCols" :data="formData" :rules="formRules" labelWidth="100" ref="form">
  4. <el-select v-model="formData.communityId" placeholder="请选择所属社区" clearable slot="communityId" @change="communityChange">
  5. <el-option v-for="(item, index) in communityArr" :key="index" :label="item.communityName" :value="item.id"></el-option>
  6. </el-select>
  7. <el-select v-model="formData.buildingId" placeholder="请选择楼栋" clearable slot="buildingId" @change="buildingChange">
  8. <el-option v-for="(item, index) in buildingArr" :key="index" :label="item.label" :value="item.id"></el-option>
  9. </el-select>
  10. <el-select v-model="formData.unit" placeholder="请选择单元" clearable slot="unit">
  11. <el-option v-for="(item, index) in unitArr" :key="index" :label="item.label" :value="item.id"></el-option>
  12. </el-select>
  13. <template slot="latitude">
  14. <el-input v-model="formData.latitude" placeholder="请选择经纬坐标">
  15. <i slot="suffix" class="zoniot_font zoniot-icon-dizhi" @click="QueryClick"></i>
  16. </el-input>
  17. </template>
  18. </zz-form>
  19. </div>
  20. </template>
  21. <script >
  22. import MapPopup from '@/components/mapPopup/index.vue';
  23. export default {
  24. props: ['params'],
  25. components: {
  26. MapPopup
  27. },
  28. data() {
  29. return {
  30. formData: {
  31. communityId: '',
  32. pointName: '',
  33. pointNo: '',
  34. buildingId: '',
  35. unit: '',
  36. latitude: '',
  37. longitude: ''
  38. },
  39. initDot: [],
  40. communityTre: [],
  41. formRules: {
  42. communityId: [this.$valid.selectRequired('公司')],
  43. pointName: [this.$valid.inputRequired('巡更点名称')],
  44. pointNo: [this.$valid.inputRequired('巡更点编号')],
  45. latitude: [this.$valid.inputRequired('经纬度坐标'), this.$valid.selectRequired('经纬度坐标')]
  46. },
  47. formCols: [
  48. [
  49. {
  50. label: '所属社区',
  51. prop: 'communityId',
  52. slot: 'communityId'
  53. },
  54. {
  55. label: '楼栋',
  56. prop: 'buildingId',
  57. slot: 'buildingId'
  58. },
  59. {
  60. label: '单元',
  61. prop: 'unit',
  62. slot: 'unit'
  63. },
  64. {
  65. label: '巡更点名称',
  66. prop: 'pointName',
  67. input: true
  68. },
  69. {
  70. label: '巡更点编号',
  71. prop: 'pointNo',
  72. input: true
  73. },
  74. {
  75. label: '经纬度坐标',
  76. prop: 'latitude',
  77. slot: 'latitude'
  78. }
  79. ]
  80. ],
  81. communityArr: [],
  82. buildingArr: [],
  83. unitArr: [],
  84. backfill: false,
  85. mapPopUpStatus: false //地图弹出框
  86. };
  87. },
  88. watch: {},
  89. methods: {
  90. QueryClick() {
  91. new Promise((resolve) => {
  92. let title = '选择坐标';
  93. this.$store.dispatch('addPopup', {
  94. url: '/patrolManagement/popups/popMap.vue',
  95. width: '500px',
  96. height: '500px',
  97. props: {
  98. callback: resolve
  99. },
  100. title: title
  101. });
  102. }).then((e) => {
  103. this.initDot = [e.lat, e.lng];
  104. this.formData.latitude = `${e.lat},${e.lng}`;
  105. this.formData.longitude = e.lng;
  106. });
  107. },
  108. CheckChinese(val, name) {
  109. var reg = new RegExp('[\\u4E00-\\u9FFF]+', 'g');
  110. let newVal = val;
  111. if (!reg.test(val)) {
  112. newVal = val + name;
  113. }
  114. return newVal;
  115. },
  116. nestedLoop(arr, type, thisArr, e, resolve) {
  117. let newArr = [];
  118. arr.map((item) => {
  119. if (item.id == e && !!item.children) {
  120. item.children.map((itemUnit) => {
  121. if (itemUnit.type == type) {
  122. newArr.push({
  123. label: this.CheckChinese(itemUnit.name, type == 'unit' ? '单元' : '楼栋'),
  124. id: type == 'unit' ? itemUnit.value : Number(itemUnit.value),
  125. type: itemUnit.type,
  126. children: itemUnit.children
  127. });
  128. }
  129. });
  130. }
  131. });
  132. this[thisArr] = newArr;
  133. },
  134. submit() {
  135. new Promise((resolve) => {
  136. this.$refs.form.validate(resolve);
  137. }).then(() => {
  138. var loading = this.$loading();
  139. let url = '/sc-community/patrol/point/add';
  140. let initData = {
  141. communityId: this.formData.communityId,
  142. pointName: this.formData.pointName,
  143. pointNo: this.formData.pointNo,
  144. buildingId: this.formData.buildingId,
  145. unit: this.formData.unit,
  146. latitude: this.initDot[0],
  147. longitude: this.initDot[1]
  148. };
  149. if (this.params.todo == 'edit') {
  150. url = '/sc-community/patrol/point/update';
  151. initData.id = this.formData.id;
  152. }
  153. this.$http
  154. .post(url, initData)
  155. .then(({ status, msg }) => {
  156. if (status == 0) {
  157. this.$message.success(msg);
  158. this.params.callback();
  159. this.$emit('close');
  160. } else {
  161. this.$message.error(msg);
  162. }
  163. loading.close();
  164. })
  165. .catch(() => {
  166. loading.close();
  167. });
  168. });
  169. },
  170. communityChange(e) {
  171. this.formData.buildingId = '';
  172. this.formData.unit = '';
  173. this.nestedLoop(this.communityTre, 'building', 'buildingArr', e);
  174. },
  175. buildingChange(e) {
  176. this.formData.unit = '';
  177. this.nestedLoop(this.buildingArr, 'unit', 'unitArr', e);
  178. }
  179. },
  180. created() {
  181. this.communityTre = this.params.communityTre;
  182. this.communityArr = this.params.communityArr;
  183. if (this.params.todo == 'edit') {
  184. let newData = this.params.data;
  185. this.formData = newData;
  186. this.nestedLoop(this.communityTre, 'building', 'buildingArr', newData.communityId);
  187. this.nestedLoop(this.buildingArr, 'unit', 'unitArr', newData.buildingId);
  188. this.initDot = [newData.latitude, newData.longitude];
  189. this.formData.latitude = `${newData.latitude},${newData.longitude}`;
  190. }
  191. }
  192. };
  193. </script>