Browse Source

青苗接口

duy 1 year ago
parent
commit
01b804ba6a
2 changed files with 151 additions and 78 deletions
  1. 149 73
      src/views/base/crops.vue
  2. 2 5
      src/views/base/land.vue

+ 149 - 73
src/views/base/crops.vue

@@ -3,90 +3,95 @@
         <template #left>
             <div class="hc-layout-tree-box">
                 <el-scrollbar>
-                    <HcTreeData @nodeTap="treeNodeTap"/>
+                    <HcTreeData @nodeTap="treeNodeTap" />
                 </el-scrollbar>
             </div>
         </template>
         <HcCard>
             <template #header>
                 <div class="w-48">
-                    <el-select v-model="searchForm.projectType" block clearable placeholder="请选择土地性质" size="large">
-                        <el-option label="选项1" value="选项1"/>
-                        <el-option label="选项2" value="选项2"/>
+                    <el-select v-model="searchForm.compensationType" block clearable placeholder="请选择补偿性质" size="large">
+                        <el-option v-for="item in compensationType" :key="item.id" :label="item.dictValue" :value="item.dictKey" />
                     </el-select>
                 </div>
                 <div class="w-64 ml-2">
-                    <el-input v-model="searchForm.queryValue" clearable placeholder="请输入名称进行查询" size="large"/>
+                    <el-input v-model="searchForm.name" clearable placeholder="请输入名称进行查询" size="large" />
                 </div>
                 <div class="ml-4">
-                    <el-button type="primary" @click="searchClick" size="large">
-                        <HcIcon name="search-2"/>
+                    <el-button type="primary" size="large" @click="searchClick">
+                        <HcIcon name="search-2" />
                         <span>搜索</span>
                     </el-button>
                 </div>
             </template>
             <template #extra>
                 <el-button size="large" type="primary" hc-btn @click="addRowClick">
-                    <HcIcon name="add"/>
+                    <HcIcon name="add" />
                     <span>新增</span>
                 </el-button>
                 <el-button size="large" type="danger" hc-btn>
-                    <HcIcon name="delete-bin"/>
+                    <HcIcon name="delete-bin" />
                     <span>删除</span>
                 </el-button>
             </template>
-            <HcTable :column="tableColumn" :datas="tableData" :loading="tableLoading" isCheck @selection-change="tableSelectionChange">
-                <template #action="{row,index}">
-                    <el-button size="small" type="warning" @click="viewRowClick(row)">查看</el-button>
-                    <el-button size="small" type="primary" @click="editRowClick(row)">编辑</el-button>
-                    <el-button size="small" type="danger">删除</el-button>
+            <HcTable :column="tableColumn" :datas="tableData" :loading="tableLoading" is-check @selection-change="tableSelectionChange">
+                <template #action="{ row, index }">
+                    <el-button size="small" type="warning" @click="viewRowClick(row)">
+                        查看
+                    </el-button>
+                    <el-button size="small" type="primary" @click="editRowClick(row)">
+                        编辑
+                    </el-button>
+                    <el-button size="small" type="danger">
+                        删除
+                    </el-button>
                 </template>
             </HcTable>
             <template #action>
-                <HcPages :pages="searchForm" @change="pageChange"/>
+                <HcPages :pages="searchForm" @change="pageChange" />
             </template>
         </HcCard>
 
-        <!--新增/编辑-->
-        <HcDialog isToBody bgColor="white" :show="rowModal" isTable widths="80%" :padding="false"
-                  :title="formModel.id?'编辑':'新增'" @save="rowModalSave" @close="rowModalClose"
+        <!-- 新增/编辑 -->
+        <HcDialog
+            is-to-body bg-color="white" :show="rowModal" is-table widths="80%" :padding="false"
+            :title="formModel.id ? '编辑' : '新增'" :loading="submitLoading" @save="rowModalSave" @close="rowModalClose" 
         >
             <HcCard>
                 <template #header>
                     <el-form ref="formRef" inline :model="formModel" :rules="formRules" size="large">
-                        <el-form-item label="名称:" prop="key1">
-                            <el-input v-model="formModel.key1"/>
+                        <el-form-item label="名称:" prop="name">
+                            <el-input v-model="formModel.name" />
                         </el-form-item>
                         <el-form-item label="补偿性质:">
-                            <el-select block v-model="formModel.key2">
-                                <el-option label="选项1" value="选项1"/>
-                                <el-option label="选项2" value="选项2"/>
+                            <el-select v-model="formModel.compensationType" block>
+                                <el-option v-for="item in compensationType" :key="item.id" :label="item.dictValue" :value="item.dictKey" />
                             </el-select>
                         </el-form-item>
                     </el-form>
                 </template>
                 <template #extra>
-                    <el-button size="large" type="success" hc-btn>
-                        <HcIcon name="add"/>
+                    <el-button size="large" type="success" hc-btn @click="addChildRowClick">
+                        <HcIcon name="add" />
                         <span>新增</span>
                     </el-button>
                 </template>
                 <HcTable :column="tableColumn1" :datas="tableData1">
-                    <template #key1="{row,index}">
-                        <el-input v-model="row.key1"/>
+                    <template #specificationName="{ row, index }">
+                        <el-input v-model="row.specificationName" />
                     </template>
-                    <template #key2="{row,index}">
-                        <el-input v-model="row.key2"/>
+                    <template #unitName="{ row, index }">
+                        <el-input v-model="row.unitName" />
                     </template>
-                    <template #key3="{row,index}">
-                        <el-input v-model="row.key3"/>
+                    <template #governmentStand="{ row, index }">
+                        <el-input v-model="row.governmentStand" />
                     </template>
-                    <template #key4="{row,index}">
-                        <el-input v-model="row.key4"/>
+                    <template #agreementStand="{ row, index }">
+                        <el-input v-model="row.agreementStand" />
                     </template>
-                    <template #action="{row,index}">
+                    <template #action="{ row, index }">
                         <el-button size="small" type="danger">
-                            <HcIcon name="delete-bin"/>
+                            <HcIcon name="delete-bin" />
                             <span>删除</span>
                         </el-button>
                     </template>
@@ -94,51 +99,78 @@
             </HcCard>
         </HcDialog>
 
-        <!--查看-->
-        <HcDialog isToBody bgColor="white" :footer="false" :show="rowViewModal" isTable widths="80%" :padding="false" title="查看" @close="rowViewModalClose">
+        <!-- 查看 -->
+        <HcDialog is-to-body bg-color="white" :footer="false" :show="rowViewModal" is-table widths="80%" :padding="false" title="查看" @close="rowViewModalClose">
             <HcCard>
                 <template #header>
                     <el-form inline :model="formModel" size="large" disabled>
                         <el-form-item label="名称:" prop="key1">
-                            <el-input v-model="formModel.key1"/>
+                            <el-input v-model="formModel.key1" />
                         </el-form-item>
                         <el-form-item label="补偿性质:">
-                            <el-select block v-model="formModel.key2">
-                                <el-option label="选项1" value="选项1"/>
-                                <el-option label="选项2" value="选项2"/>
+                            <el-select v-model="formModel.key2" block>
+                                <el-option v-for="item in compensationType" :key="item.id" :label="item.dictValue" :value="item.dictKey" />
                             </el-select>
                         </el-form-item>
                     </el-form>
                 </template>
-                <HcTable :column="tableColumn1" :datas="tableData1"/>
+                <HcTable :column="tableColumn1" :datas="tableData1" />
             </HcCard>
         </HcDialog>
-
     </HcPageLayout>
 </template>
 
 <script setup>
-import {ref} from "vue";
+import { onMounted, ref } from 'vue'
+import cropsApi from '~api/base/crops.js'
+import { getDictInfo } from '~api/other'
+import { arrToId, formValidate, getArrValue, getObjValue } from 'js-fast-way'
+import { useAppStore } from '~src/store'
 
-//树节点被点击
-const treeNodeTap = ({node, data}) => {
 
+onMounted(()=>{
+    getTableData()
+    getCompensationTypeType()
+})
+
+const useAppState = useAppStore()
+const projectId = ref(useAppState.getProjectId)
+
+
+//获取补偿性质
+const compensationType = ref([])
+const getCompensationTypeType = async ()=>{
+    const { error, code, data } = await getDictInfo('compensation_type')
+    if (!error && code === 200) {
+        compensationType.value = getArrValue(data)
+        compensationType.value.forEach((ele)=>{
+            ele.dictKey = parseInt(ele.dictKey)
+        })
+       
+    } else {
+        compensationType.value = []
+    }
+}
+//树节点被点击
+const treeNodeTap = ({ node, data }) => {
+    searchForm.value.areaId = data.id
+    getTableData()
 }
 
 //搜索表单
 const searchForm = ref({
-    projectType: null, queryValue: null, startTime: null, endTime: null,
-    current: 1, size: 20, total: 0
+    compensationType: null, name: null, startTime: null, endTime: null,
+    current: 1, size: 20, total: 0,
 })
 
 //搜索
 const searchClick = () => {
-    searchForm.value.current = 1;
+    searchForm.value.current = 1
     getTableData()
 }
 
 //分页被点击
-const pageChange = ({current, size}) => {
+const pageChange = ({ current, size }) => {
     searchForm.value.current = current
     searchForm.value.size = size
     getTableData()
@@ -147,18 +179,30 @@ const pageChange = ({current, size}) => {
 //获取数据
 const tableLoading = ref(false)
 const tableColumn = [
-    {key: 'key1', name: '补偿类型'},
-    {key: 'key2', name: '名称'},
-    {key: 'action', name: '操作', width: '190', align: 'center'},
+    { key: 'compensationTypeName', name: '补偿类型' },
+    { key: 'name', name: '名称' },
+    { key: 'action', name: '操作', width: '190', align: 'center' },
 ]
 const tableData = ref([
-    {id: 1, key1: 'xxxx', key2: 'xxxx', key3: '65632'},
-    {id: 2, key1: 'xxxx', key2: 'xxxx', key3: '65632'},
-    {id: 3, key1: 'xxxx', key2: 'xxxx', key3: '65632'},
-    {id: 4, key1: 'xxxx', key2: 'xxxx', key3: '65632'},
+    { id: 1, key1: 'xxxx', key2: 'xxxx', key3: '65632' },
+    { id: 2, key1: 'xxxx', key2: 'xxxx', key3: '65632' },
+    { id: 3, key1: 'xxxx', key2: 'xxxx', key3: '65632' },
+    { id: 4, key1: 'xxxx', key2: 'xxxx', key3: '65632' },
 ])
-const getTableData = () => {
-
+const getTableData = async () => {
+    tableLoading.value = true
+    const { error, code, data } = await cropsApi.getPage({
+        ...searchForm.value,
+        projectId: projectId.value,
+    })
+    tableLoading.value = false
+    if (!error && code === 200) {
+        tableData.value = getArrValue(data['records'])
+        searchForm.value.total = data['total'] || 0
+    } else {
+        tableData.value = []
+        searchForm.value.total = 0
+    }
 }
 
 //多选事件
@@ -171,22 +215,18 @@ const rowModal = ref(false)
 const formRef = ref(null)
 const formModel = ref({})
 const formRules = {
-    key1: [{required: true, message: '请输入名称', trigger: 'blur'}],
+    name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
 }
 
 //表格表单数据
 const tableColumn1 = [
-    {key: 'key1', name: '规格名称'},
-    {key: 'key2', name: '单位名称'},
-    {key: 'key3', name: '政府补偿标准'},
-    {key: 'key4', name: '两方协议补偿标准'},
-    {key: 'action', name: '操作', width: '100', align: 'center'},
+    { key: 'specificationName', name: '规格名称' },
+    { key: 'unitName', name: '单位名称' },
+    { key: 'governmentStand', name: '政府补偿标准' },
+    { key: 'agreementStand', name: '两方协议补偿标准' },
+    { key: 'action', name: '操作', width: '100', align: 'center' },
 ]
 const tableData1 = ref([
-    {id: 1, key1: 'xxxx', key2: 'xxxx', key3: '65632'},
-    {id: 2, key1: 'xxxx', key2: 'xxxx', key3: '65632'},
-    {id: 3, key1: 'xxxx', key2: 'xxxx', key3: '65632'},
-    {id: 4, key1: 'xxxx', key2: 'xxxx', key3: '65632'},
 ])
 
 //新增
@@ -197,13 +237,45 @@ const addRowClick = () => {
 
 //编辑
 const editRowClick = (row) => {
-    formModel.value = row
+    getDetail(row.id)
     rowModal.value = true
 }
-
+//获取详情
+const getDetail = async (id)=>{
+    const { error, code, data } = await cropsApi.getDetail({
+        id,
+    })
+    if (!error && code === 200) {
+        formModel.value = getObjValue(data)
+        tableData1.value = formModel.value.childrenList
+    
+    } else {
+        formModel.value = {}
+        tableData1.value = []
+    }
+ }
+const submitLoading = ref(false)
 //保存
-const rowModalSave = () => {
-
+const rowModalSave = async () => {
+    console.log(formModel.value, 'value')
+    console.log(tableData1.value, 'tableData1')
+    const res = await formValidate(formRef.value)
+    if (res) {
+        submitLoading.value = true
+        const form = formModel.value
+        form.projectId = projectId.value
+        form.areaId = searchForm.value.areaId
+        form.childrenList = tableData1.value
+        const { error, code, msg } = await cropsApi.addOrUpdate(form)
+        //判断状态
+        submitLoading.value = false
+        if (!error && code === 200) {
+            window.$message?.success(msg)
+            rowModal.value = false
+            getTableData()
+            
+        } 
+    }
 }
 
 //关闭弹窗
@@ -220,6 +292,10 @@ const viewRowClick = (row) => {
 const rowViewModalClose = () => {
     rowViewModal.value = false
 }
+//新增子
+const addChildRowClick = ()=>{
+    tableData1.value.push({})
+}
 </script>
 
 <style lang="scss" scoped>

+ 2 - 5
src/views/base/land.vue

@@ -71,9 +71,9 @@
 </template>
 
 <script setup>
-import { onActivated, onMounted, ref } from 'vue'
+import { onMounted, ref } from 'vue'
 import landApi from '~api/base/land.js'
-import { arrToId, formValidate, getArrValue, getObjValue } from 'js-fast-way'
+import { arrToId, formValidate, getArrValue } from 'js-fast-way'
 import { useAppStore } from '~src/store'
 import { getDictInfo } from '~api/other'
 import { delMessageV2 } from '~com/message/index.js'
@@ -87,9 +87,7 @@ onMounted(()=>{
     getNatureType()
 })
 //获取土地性质
-
 const natureType = ref([])
-//获取区域
 const getNatureType = async ()=>{
     const { error, code, data } = await getDictInfo('land_nature')
     if (!error && code === 200) {
@@ -142,7 +140,6 @@ const getTableData = async () => {
     const { error, code, data } = await landApi.getPage({
         ...searchForm.value,
         projectId: projectId.value,
-        type:1,
     })
     tableLoading.value = false
     if (!error && code === 200) {