Browse Source

三级区域

master
zhanyunjiu 3 years ago
parent
commit
ba60baa316
  1. 54
      src/views/farm/area/index.vue

54
src/views/farm/area/index.vue

@ -36,12 +36,10 @@
<el-table-column label="区域名" align="center" prop="name" /> <el-table-column label="区域名" align="center" prop="name" />
<el-table-column label="唯一占用" align="center" prop="occupied" > <el-table-column label="唯一占用" align="center" prop="occupied" >
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="danger" v-if="scope.row.occupied">未占用</el-button> <el-button type="danger" v-if="!scope.row.occupied">未占用</el-button>
<el-button type="success" v-if="!scope.row.occupied">已占用</el-button> <el-button type="success" v-if="scope.row.occupied">已占用</el-button>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="面积(亩)" align="center" prop="area" /> <el-table-column label="面积(亩)" align="center" prop="area" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180"> <el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope"> <template slot-scope="scope">
@ -64,25 +62,15 @@
<!-- 对话框(添加 / 修改) --> <!-- 对话框(添加 / 修改) -->
<el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" width="500px" append-to-body> <el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="上级" prop="projectId"> <el-form-item label="上级区域选址" prop="twoAreaList">
<el-select v-model="form.parentId" placeholder="请选择"> <el-cascader :options="twoAreaList" :props="{emitPath:false, checkStrictly:true}" v-model="form.parentId" placeholder="不选择,默认为第一级区域"></el-cascader>
<el-option
v-for="item in firstList"
:key="item.id"
:label="item.name"
:value="item.id">
{{item.name}}
</el-option>
</el-select>
</el-form-item> </el-form-item>
<el-form-item label="区域名" prop="name"> <el-form-item label="区域名" prop="name">
<el-input v-model="form.name" placeholder="请输入" /> <el-input v-model="form.name" placeholder="请输入" />
</el-form-item> </el-form-item>
<el-form-item label="面积(亩)" prop="area"> <el-form-item label="面积(亩)" prop="area">
<el-input v-model="form.area" placeholder="请输入" /> <el-input v-model="form.area" placeholder="请输入" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button> <el-button type="primary" @click="submitForm"> </el-button>
@ -128,10 +116,11 @@ export default {
rules: { rules: {
}, },
allList:[],
firstList:[], firstList:[],
secondList:[], assembleList:[],
assembleList:[]
allAreaList:[], //
twoAreaList:[] //
}; };
}, },
created() { created() {
@ -146,6 +135,7 @@ export default {
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
// //
getAreaPage(params).then(response => { getAreaPage(params).then(response => {
this.allAreaList = response.data.list;
this.list = response.data.list; this.list = response.data.list;
this.total = response.data.total; this.total = response.data.total;
let filterList = this.list.filter(t => t.parentId == 0); let filterList = this.list.filter(t => t.parentId == 0);
@ -163,6 +153,7 @@ export default {
}) })
oneList.push({id:one.id, name:one.name, occupied:one.occupied, area:one.area, createTime:one.createTime, children:twoList}); oneList.push({id:one.id, name:one.name, occupied:one.occupied, area:one.area, createTime:one.createTime, children:twoList});
}) })
this.list = oneList; this.list = oneList;
this.loading = false; this.loading = false;
}); });
@ -194,7 +185,7 @@ export default {
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.reset(); this.reset();
this.firstList = this.allList.filter(t => t.parentId == 0); this.assembleArea();
this.open = true; this.open = true;
this.title = "添加"; this.title = "添加";
}, },
@ -202,6 +193,7 @@ export default {
handleUpdate(row) { handleUpdate(row) {
this.reset(); this.reset();
const id = row.id; const id = row.id;
this.assembleArea();
getArea(id).then(response => { getArea(id).then(response => {
this.form = response.data; this.form = response.data;
this.open = true; this.open = true;
@ -256,6 +248,28 @@ export default {
this.$download.excel(response, '${table.classComment}.xls'); this.$download.excel(response, '${table.classComment}.xls');
this.exportLoading = false; this.exportLoading = false;
}).catch(() => {}); }).catch(() => {});
},
assembleArea(){
//
let firstLsit = this.allAreaList.filter(t => t.parentId == 0);
let secondList = [];
//
let oneList = [];
firstLsit.forEach(first =>{
let list = this.allAreaList.filter(area => area.parentId == first.id);
let twoList = [];
list.forEach(item => {
secondList.push(item);
twoList.push({value:item.id, label:item.name});
});
if(twoList.length != 0){
oneList.push({value:first.id, label:first.name, children:twoList});
}else{
oneList.push({value:first.id, label:first.name});
}
});
this.twoAreaList = oneList;
} }
} }
}; };

Loading…
Cancel
Save