修改基地参数
parent
d077d59f70
commit
65c727efb9
|
|
@ -113,7 +113,7 @@ export function getTreeData(
|
|||
condition = 0,
|
||||
isNull = true,
|
||||
) {
|
||||
let arr = []
|
||||
const arr = []
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (data[i][pidName] == pid) {
|
||||
|
|
@ -139,14 +139,14 @@ export function getTreeData(
|
|||
|
||||
// 获取近7的时间
|
||||
export function getWeek() {
|
||||
let toData = new Date(new Date().toLocaleDateString()).getTime()
|
||||
const toData = new Date(new Date().toLocaleDateString()).getTime()
|
||||
//今天
|
||||
let todayStart = toData
|
||||
const todayStart = toData
|
||||
//昨天
|
||||
let yesterdayStart = toData - 3600 * 24 * 1000
|
||||
let yesterdayEnd = yesterdayStart + 24 * 60 * 60 * 1000 - 1
|
||||
const yesterdayStart = toData - 3600 * 24 * 1000
|
||||
const yesterdayEnd = yesterdayStart + 24 * 60 * 60 * 1000 - 1
|
||||
//最近7天
|
||||
let past7daysStart = todayStart - 7 * 3600 * 24 * 1000
|
||||
const past7daysStart = todayStart - 7 * 3600 * 24 * 1000
|
||||
// const date = new Date()
|
||||
// const year = date.getFullYear()
|
||||
// const month = date.getMonth()
|
||||
|
|
@ -164,12 +164,12 @@ export function getWeek() {
|
|||
|
||||
// 获取近一月的数据
|
||||
export function getMonth() {
|
||||
let toData = new Date(new Date().toLocaleDateString()).getTime()
|
||||
const toData = new Date(new Date().toLocaleDateString()).getTime()
|
||||
//昨天
|
||||
let yesterdayStart = toData - 3600 * 24 * 1000
|
||||
let yesterdayEnd = yesterdayStart + 24 * 60 * 60 * 1000 - 1
|
||||
const yesterdayStart = toData - 3600 * 24 * 1000
|
||||
const yesterdayEnd = yesterdayStart + 24 * 60 * 60 * 1000 - 1
|
||||
//最近30天
|
||||
let past30daysStart = toData - 30 * 3600 * 24 * 1000
|
||||
const past30daysStart = toData - 30 * 3600 * 24 * 1000
|
||||
// const date = new Date()
|
||||
// const year = date.getFullYear()
|
||||
// const month = date.getMonth()
|
||||
|
|
@ -198,3 +198,20 @@ export function jsonString(value) {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 加法函数(精度丢失问题)
|
||||
export function accAdd(arg1, arg2) {
|
||||
let r1, r2, m
|
||||
try {
|
||||
r1 = arg1.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r1 = 0
|
||||
}
|
||||
try {
|
||||
r2 = arg2.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r2 = 0
|
||||
}
|
||||
m = Math.pow(10, Math.max(r1, r2))
|
||||
return (arg1 * m + arg2 * m) / m
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ export const columns: BasicColumn[] = [
|
|||
title: '基地面积',
|
||||
dataIndex: 'areas',
|
||||
},
|
||||
{
|
||||
title: '种养殖面积',
|
||||
dataIndex: 'cultivated',
|
||||
},
|
||||
{
|
||||
title: '基地就业人数',
|
||||
dataIndex: 'workforce',
|
||||
|
|
@ -101,6 +105,12 @@ export const accountFormSchema: FormSchema[] = [
|
|||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'cultivated',
|
||||
label: '种养殖面积',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'workforce',
|
||||
label: '基地人数',
|
||||
|
|
|
|||
|
|
@ -4,23 +4,112 @@
|
|||
@register="registerDrawer"
|
||||
showFooter
|
||||
:title="getTitle"
|
||||
width="500px"
|
||||
width="600px"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<BasicForm @register="registerForm"> </BasicForm>
|
||||
<BasicForm @register="registerForm">
|
||||
<template #extends="{ model, field }">
|
||||
<template v-for="(item, index) in model[field]" :key="index">
|
||||
<div v-for="(item1, i) in item.value" :key="i">
|
||||
<Row>
|
||||
<Col :span="15">
|
||||
<FormItem
|
||||
:labelCol="{ span: 13 }"
|
||||
:label="i == 0 ? item.name : ` `"
|
||||
:name="['extends', i, 'value']"
|
||||
:rules="{
|
||||
required: false,
|
||||
message: '请输入',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<DatePicker
|
||||
format="YYYY"
|
||||
valueFormat="YYYY"
|
||||
v-model:value="item1.year"
|
||||
picker="year"
|
||||
/>
|
||||
</FormItem>
|
||||
</Col>
|
||||
<Col :span="9">
|
||||
<FormItem
|
||||
:labelCol="{ span: 2 }"
|
||||
:name="['extends', i, 'value']"
|
||||
:label="` `"
|
||||
:rules="{
|
||||
required: false,
|
||||
message: '请输入',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<div class="flex items-center">
|
||||
<div class="w-9/10">
|
||||
<InputNumber
|
||||
class="!mr-10px"
|
||||
v-model:value="item1.value"
|
||||
placeholder="请输入"
|
||||
:addon-after="item.unit"
|
||||
/>
|
||||
</div>
|
||||
<PlusCircleOutlined
|
||||
v-if="i === 0"
|
||||
class="cursor-pointer"
|
||||
@click="addDomain(item)"
|
||||
/>
|
||||
<MinusCircleOutlined
|
||||
v-else
|
||||
class="cursor-pointer"
|
||||
@click="removeDomain(item, i)"
|
||||
/>
|
||||
</div>
|
||||
</FormItem>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</BasicForm>
|
||||
</BasicDrawer>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
const defaultData = {
|
||||
chart_nongye: {
|
||||
label: '统计数据-农业',
|
||||
unit: '万元',
|
||||
},
|
||||
chart_yuye: {
|
||||
label: '统计数据-渔业',
|
||||
unit: '万元',
|
||||
},
|
||||
chart_xumuye: {
|
||||
label: '统计数据-畜牧业',
|
||||
unit: '万元',
|
||||
},
|
||||
chart_lingye: {
|
||||
label: '统计数据-林业',
|
||||
unit: '万元',
|
||||
},
|
||||
chart_activity: {
|
||||
label: '统计数据-其他',
|
||||
unit: '万元',
|
||||
},
|
||||
}
|
||||
import { ref, computed, unref } from 'vue'
|
||||
import { BasicForm, useForm } from '/@/components/Form/index'
|
||||
import { accountFormSchema } from './city.data'
|
||||
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'
|
||||
import { addaGriculturalBasic, editGriculturalBasic } from '/@/api/sys/user'
|
||||
import { isArray, isObject } from '/@/utils/is'
|
||||
import { FormItem, Row, Col, DatePicker, InputNumber } from 'ant-design-vue'
|
||||
import { MinusCircleOutlined, PlusCircleOutlined } from '@ant-design/icons-vue'
|
||||
import { concat } from 'lodash-es'
|
||||
import dayjs from 'dayjs'
|
||||
const emits = defineEmits(['success', 'register'])
|
||||
const isUpdate = ref(false)
|
||||
const getTitle = computed(() => (!isUpdate.value ? '新增街镇' : '编辑街镇'))
|
||||
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
|
||||
labelWidth: 120,
|
||||
// labelWidth: 120,
|
||||
labelCol: { span: 8 },
|
||||
baseColProps: { span: 24 },
|
||||
schemas: accountFormSchema,
|
||||
showActionButtonGroup: false,
|
||||
|
|
@ -30,8 +119,49 @@
|
|||
setDrawerProps({ confirmLoading: false })
|
||||
isUpdate.value = data?.isUpdate
|
||||
if (unref(isUpdate)) {
|
||||
console.log(data.extends)
|
||||
const defaultObj = {}
|
||||
|
||||
Object.keys(defaultData).forEach((item) => {
|
||||
defaultObj[item] = data.extends[item] ?? {}
|
||||
})
|
||||
|
||||
const tempData = Object.keys(defaultObj).reduce((pre, cur) => {
|
||||
const currentData = defaultData[cur]
|
||||
const obj = {
|
||||
name: currentData.label,
|
||||
unit: currentData.unit,
|
||||
slug: cur,
|
||||
}
|
||||
const extend = defaultObj[cur]
|
||||
if (isObject(extend) || isArray(extend)) {
|
||||
const temp = []
|
||||
|
||||
if (Object.keys(extend).length === 0) {
|
||||
temp.push({
|
||||
value: '',
|
||||
year: null,
|
||||
})
|
||||
}
|
||||
|
||||
for (const key in extend) {
|
||||
temp.push({
|
||||
value: extend[key],
|
||||
year: dayjs(key + '', 'YYYY'),
|
||||
})
|
||||
}
|
||||
|
||||
return concat(pre, {
|
||||
...obj,
|
||||
isMore: true,
|
||||
value: temp,
|
||||
})
|
||||
}
|
||||
}, [])
|
||||
setFieldsValue({
|
||||
...data,
|
||||
...Object.assign({}, data, {
|
||||
extends: tempData,
|
||||
}),
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
@ -39,12 +169,26 @@
|
|||
try {
|
||||
const values = await validate()
|
||||
values.type = 2
|
||||
const params = {}
|
||||
values.extends.forEach((e) => {
|
||||
const temp = {}
|
||||
e.value.forEach((el) => {
|
||||
if (el.year) temp[dayjs(el.year).get('year')] = el.value
|
||||
})
|
||||
params[e.slug] = temp
|
||||
})
|
||||
|
||||
const data = {
|
||||
...values,
|
||||
extends: params,
|
||||
}
|
||||
|
||||
if (values.id) {
|
||||
// 修改
|
||||
await editGriculturalBasic(values.id, values)
|
||||
await editGriculturalBasic(values.id, data)
|
||||
} else {
|
||||
// 新增
|
||||
await addaGriculturalBasic(values)
|
||||
await addaGriculturalBasic(data)
|
||||
}
|
||||
closeDrawer()
|
||||
emits('success')
|
||||
|
|
@ -52,4 +196,15 @@
|
|||
setDrawerProps({ confirmLoading: false })
|
||||
}
|
||||
}
|
||||
|
||||
const addDomain = (item) => {
|
||||
item.value.push({
|
||||
value: '',
|
||||
year: '',
|
||||
})
|
||||
}
|
||||
|
||||
const removeDomain = (item, index) => {
|
||||
item.value.splice(index, 1)
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ export const columns: BasicColumn[] = [
|
|||
title: '街镇面积',
|
||||
dataIndex: 'areas',
|
||||
},
|
||||
{
|
||||
title: '耕地面积',
|
||||
dataIndex: 'cultivated',
|
||||
},
|
||||
{
|
||||
title: '街镇人数',
|
||||
dataIndex: 'workforce',
|
||||
|
|
@ -88,6 +92,12 @@ export const accountFormSchema: FormSchema[] = [
|
|||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'cultivated',
|
||||
label: '耕地面积',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'workforce',
|
||||
label: '街镇人数',
|
||||
|
|
@ -132,6 +142,12 @@ export const accountFormSchema: FormSchema[] = [
|
|||
required: false,
|
||||
component: 'InputTextArea',
|
||||
},
|
||||
{
|
||||
field: 'extends',
|
||||
label: '',
|
||||
component: 'Input',
|
||||
slot: 'extends',
|
||||
},
|
||||
]
|
||||
export const searchFormSchema1: FormSchema[] = [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, computed, unref, ref, watchEffect } from 'vue'
|
||||
|
||||
import { defineComponent, computed, unref, ref } from 'vue'
|
||||
import { accAdd } from '/@/utils/index'
|
||||
export default defineComponent({
|
||||
// :axis="x_axis" :data="series"
|
||||
props: {
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
unref(props.data).reduce((p, c) => {
|
||||
p.push({
|
||||
name: c.name,
|
||||
value: c.data.reduce((p, c) => (p += parseFloat(c ?? 0)), 0),
|
||||
value: c.data.reduce((p, c) => accAdd(p, c ?? 0), 0),
|
||||
})
|
||||
return p
|
||||
}, []),
|
||||
|
|
|
|||
Loading…
Reference in New Issue