123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <template>
- <div>
- <zz-form :cols="formCols" :data="formData" :rules="formRules" labelWidth="100" ref="form">
- <el-select v-model="formData.communityId" placeholder="请选择所属社区" clearable slot="communityId" @change="communityChange">
- <el-option v-for="(item, index) in communityArr" :key="index" :label="item.communityName" :value="item.id"></el-option>
- </el-select>
- <el-select v-model="formData.buildingId" placeholder="请选择楼栋" clearable slot="buildingId" @change="buildingChange">
- <el-option v-for="(item, index) in buildingArr" :key="index" :label="item.label" :value="item.id"></el-option>
- </el-select>
- <el-select v-model="formData.unit" placeholder="请选择单元" clearable slot="unit">
- <el-option v-for="(item, index) in unitArr" :key="index" :label="item.label" :value="item.id"></el-option>
- </el-select>
- <template slot="latitude">
- <el-input v-model="formData.latitude" placeholder="请选择经纬坐标">
- <i slot="suffix" class="zoniot_font zoniot-icon-dizhi" @click="QueryClick"></i>
- </el-input>
- </template>
- </zz-form>
- </div>
- </template>
- <script >
- import MapPopup from '@/components/mapPopup/index.vue';
- export default {
- props: ['params'],
- components: {
- MapPopup
- },
- data() {
- return {
- formData: {
- communityId: '',
- pointName: '',
- pointNo: '',
- buildingId: '',
- unit: '',
- latitude: '',
- longitude: ''
- },
- initDot: [],
- communityTre: [],
- formRules: {
- communityId: [this.$valid.selectRequired('公司')],
- pointName: [this.$valid.inputRequired('巡更点名称')],
- pointNo: [this.$valid.inputRequired('巡更点编号')],
- latitude: [this.$valid.inputRequired('经纬度坐标'), this.$valid.selectRequired('经纬度坐标')]
- },
- formCols: [
- [
- {
- label: '所属社区',
- prop: 'communityId',
- slot: 'communityId'
- },
- {
- label: '楼栋',
- prop: 'buildingId',
- slot: 'buildingId'
- },
- {
- label: '单元',
- prop: 'unit',
- slot: 'unit'
- },
- {
- label: '巡更点名称',
- prop: 'pointName',
- input: true
- },
- {
- label: '巡更点编号',
- prop: 'pointNo',
- input: true
- },
- {
- label: '经纬度坐标',
- prop: 'latitude',
- slot: 'latitude'
- }
- ]
- ],
- communityArr: [],
- buildingArr: [],
- unitArr: [],
- backfill: false,
- mapPopUpStatus: false //地图弹出框
- };
- },
- watch: {},
- methods: {
- QueryClick() {
- new Promise((resolve) => {
- let title = '选择坐标';
- this.$store.dispatch('addPopup', {
- url: '/patrolManagement/popups/popMap.vue',
- width: '500px',
- height: '500px',
- props: {
- callback: resolve
- },
- title: title
- });
- }).then((e) => {
- this.initDot = [e.lat, e.lng];
- this.formData.latitude = `${e.lat},${e.lng}`;
- this.formData.longitude = e.lng;
- });
- },
- CheckChinese(val, name) {
- var reg = new RegExp('[\\u4E00-\\u9FFF]+', 'g');
- let newVal = val;
- if (!reg.test(val)) {
- newVal = val + name;
- }
- return newVal;
- },
- nestedLoop(arr, type, thisArr, e, resolve) {
- let newArr = [];
- arr.map((item) => {
- if (item.id == e && !!item.children) {
- item.children.map((itemUnit) => {
- if (itemUnit.type == type) {
- newArr.push({
- label: this.CheckChinese(itemUnit.name, type == 'unit' ? '单元' : '楼栋'),
- id: type == 'unit' ? itemUnit.value : Number(itemUnit.value),
- type: itemUnit.type,
- children: itemUnit.children
- });
- }
- });
- }
- });
- this[thisArr] = newArr;
- },
- submit() {
- new Promise((resolve) => {
- this.$refs.form.validate(resolve);
- }).then(() => {
- var loading = this.$loading();
- let url = '/sc-community/patrol/point/add';
- let initData = {
- communityId: this.formData.communityId,
- pointName: this.formData.pointName,
- pointNo: this.formData.pointNo,
- buildingId: this.formData.buildingId,
- unit: this.formData.unit,
- latitude: this.initDot[0],
- longitude: this.initDot[1]
- };
- if (this.params.todo == 'edit') {
- url = '/sc-community/patrol/point/update';
- initData.id = this.formData.id;
- }
- this.$http
- .post(url, initData)
- .then(({ status, msg }) => {
- if (status == 0) {
- this.$message.success(msg);
- this.params.callback();
- this.$emit('close');
- } else {
- this.$message.error(msg);
- }
- loading.close();
- })
- .catch(() => {
- loading.close();
- });
- });
- },
- communityChange(e) {
- this.formData.buildingId = '';
- this.formData.unit = '';
- this.nestedLoop(this.communityTre, 'building', 'buildingArr', e);
- },
- buildingChange(e) {
- this.formData.unit = '';
- this.nestedLoop(this.buildingArr, 'unit', 'unitArr', e);
- }
- },
- created() {
- this.communityTre = this.params.communityTre;
- this.communityArr = this.params.communityArr;
- if (this.params.todo == 'edit') {
- let newData = this.params.data;
- this.formData = newData;
- this.nestedLoop(this.communityTre, 'building', 'buildingArr', newData.communityId);
- this.nestedLoop(this.buildingArr, 'unit', 'unitArr', newData.buildingId);
- this.initDot = [newData.latitude, newData.longitude];
- this.formData.latitude = `${newData.latitude},${newData.longitude}`;
- }
- }
- };
- </script>
|