273 lines
7.0 KiB
Vue
Raw Normal View History

2025-04-14 12:31:03 +08:00
<template>
<a-spin
:spinning="spinning"
:tip="tipContent"
>
<a-form
:model="form"
:label-col="{sm: { span: 6 } }"
:wrapper-col="{ span:14}"
ref="formRef"
>
<a-row :gutter="8">
<a-col :xs="24">
<a-form-item
label="行政区划"
required
name="zoneId"
:rules="[{ required: true, message: '请选择行政区划' }]"
>
<a-select
v-model:value="form.zoneId"
placeholder="请选择行政区划"
style="width: 85%;"
>
<a-select-option
v-for="(item) in zoneList"
:key="item.id"
:value="item.zoneId"
>{{ item.zoneName }}</a-select-option>
2025-04-23 18:08:45 +08:00
</a-select>
<!-- <a-input
style="display: none;"
v-model:value="form.zoneId"
/>
2025-04-14 12:31:03 +08:00
<a-cascader
style="width: 85%;"
:options="zoneOptions"
:load-data="loadZoneData"
2025-04-14 12:31:03 +08:00
change-on-select
placeholder="请选择行政区划"
@change="changeZone"
2025-04-23 18:08:45 +08:00
/> -->
2025-04-14 12:31:03 +08:00
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="8">
<a-col :xs="24">
<a-form-item
label="区域名称"
required
name="operationRegionName"
2025-04-14 12:31:03 +08:00
:rules="[{ required: true, message: '请输入区域名称' }]"
>
<a-input
style="width: 85%;"
v-model:value="form.operationRegionName"
2025-04-14 12:31:03 +08:00
placeholder="请输入区域名称"
/>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="8">
2025-04-14 12:31:03 +08:00
<a-col :xs="24">
<a-form-item
label="区域级别"
2025-04-14 12:31:03 +08:00
required
name="operationLevel"
:rules="[{ required: true, message: '请选择区域级别' }]"
2025-04-14 12:31:03 +08:00
>
<a-select
v-model:value="form.operationLevel"
placeholder="请选择区域级别"
2025-04-14 12:31:03 +08:00
style="width: 85%;"
>
<a-select-option
v-for="(item) in operationLevelList"
:key="item.levelId"
:value="item.levelValue"
>{{ item.levelName }}</a-select-option>
</a-select>
2025-04-14 12:31:03 +08:00
</a-form-item>
</a-col>
</a-row>
2025-04-14 12:31:03 +08:00
<a-row :gutter="8">
<a-col :xs="24">
<a-form-item
label="区域简称"
name="simpleName"
2025-04-14 12:31:03 +08:00
>
<a-input
style="width: 85%;"
v-model:value="form.simpleName"
2025-04-14 12:31:03 +08:00
placeholder="请输入区域简称"
/>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="8">
<a-col :xs="24">
<a-form-item
label="区域电子围栏"
required
name="points"
:rules="[{ required: true, message: '请选择区域电子围栏' }]"
>
<div style="display: flex;">
<a-input
style="display: none;"
v-model:value="form.points"
/>
<div style="margin-left: 20px;"> <a @click="selectMap">编辑地图</a></div>
</div>
</a-form-item>
</a-col>
</a-row>
2025-04-14 12:31:03 +08:00
</a-form>
</a-spin>
<operateRegionMap
ref="editORMapModel"
:onCallBack="onORMapCallBack"
:openTitle="openORMapTitle"
></operateRegionMap>
</template>
<script setup>
import { ref, defineProps, onMounted } from 'vue'
import operateRegionMap from '../../Urban/OperateRegionMap/index.vue'
2025-04-14 12:31:03 +08:00
import { callOperate } from '@/apis/call.js'
import { message } from 'ant-design-vue'
2025-04-23 18:08:45 +08:00
import { getCache } from '@/utils/authority';
2025-04-14 12:31:03 +08:00
const props = defineProps({
onCallBack: {
type: Function,
required: true
}
});
const formRef = ref();
const spinning = ref(false);
const tipContent = ref("加载中...");
const editORMapModel = ref(null);
const openORMapTitle = ref("");
const zoneOptions = ref([])
2025-04-23 18:08:45 +08:00
const zoneList = ref([])
const operationLevelList = ref([])
2025-04-14 12:31:03 +08:00
const form = ref({
operationRegionId: "",
operationRegionName: "",
simpleName: "",
2025-04-23 18:08:45 +08:00
zoneId: undefined,
points: [],
shapeType: 2,
radius: 0
2025-04-14 12:31:03 +08:00
});
onMounted(() => {
2025-04-23 18:08:45 +08:00
const userinfo = getCache('ebike-userinfo');
callOperate("/ebikeOrgZone/list?orgId=" + userinfo.orgId, {}, "get").then((res) => {
if (res.code != 200) {
message.error(res.message)
return
2025-04-14 12:31:03 +08:00
}
2025-04-23 18:08:45 +08:00
if (res.data) {
zoneList.value = res.data
}
})
callOperate("/ebikeRegion/operationLevelList", {}, "get").then((res) => {
if (res.code != 200) {
message.error(res.message)
return
}
if (res.data) {
operationLevelList.value = res.data
}
})
2025-04-23 18:08:45 +08:00
// callOperate("/ebikeOperateSystem/ebikeAdministrationZone", {}, "get").then(res => {
// if (res.code == 200) {
// let opt = []
// res.data.map(item => {
// opt.push({ label: item['name'], value: item['id'], isLeaf: item['isLeaf'] })
// })
// zoneOptions.value = opt;
// }
// })
2025-04-14 12:31:03 +08:00
})
const loadZoneData = (data) => {
2025-04-14 12:31:03 +08:00
if (data) {
let pindex = 0;
let parentId = data[0].value;
if (data.length > 0) {
pindex = data.length - 1;
parentId = data[pindex].value;
}
callOperate("/ebikeOperateSystem/ebikeAdministrationZone?parent_id=" + parentId, {}, "get").then(res => {
2025-04-14 12:31:03 +08:00
if (res.code == 200) {
let opt = []
res.data.map(item => {
opt.push({ label: item['name'], value: item['id'], isLeaf: item['isLeaf'] })
})
setZoneData(zoneOptions.value, 'value', parentId, 'children', opt);
2025-04-14 12:31:03 +08:00
}
})
}
}
const setZoneData = (arr, keyname, keyvalue, name, value) => {
arr.map(item => {
if (item[keyname] == keyvalue) {
item[name] = value;
}
if (item['children']) {
setZoneData(item['children'], keyname, keyvalue, name, value)
}
})
2025-04-14 12:31:03 +08:00
}
const changeZone = (data) => {
if (data.length > 0) {
form.value.zoneId = data[data.length - 1];
} else {
form.value.zoneId = "";
}
}
const selectMap = () => {
openORMapTitle.value = '绘制地图';
editORMapModel.value.showModal();
2025-04-14 12:31:03 +08:00
}
const onORMapCallBack = (data) => {
const { points, shapeType, radius } = data;
form.value.points = points;
form.value.shapeType = shapeType;
form.value.radius = radius;
2025-04-14 12:31:03 +08:00
}
const formSave = (callBack) => {
formRef.value.validate().then(() => {
tipContent.value = "保存中..."
spinning.value = true;
callOperate("/ebikeRegion/saveOperation", form.value).then(res => {
2025-04-14 12:31:03 +08:00
spinning.value = false;
if (res.code != 200) {
message.error(res.message);
if (callBack) {
callBack(false, res);
}
return;
}
2025-04-14 12:31:03 +08:00
if (callBack) {
callBack(true, res);
2025-04-14 12:31:03 +08:00
}
formRef.value.resetFields()
2025-04-14 12:31:03 +08:00
})
}).catch(error => {
if (callBack) {
callBack(false, error);
}
2025-04-14 12:31:03 +08:00
});
};
defineExpose({ formSave });
</script>