From 32107ca1dd2c3930dcedf768e3dff163ff3bca35 Mon Sep 17 00:00:00 2001 From: zhanghua <314079846@qq.com> Date: 星期四, 09 二月 2023 11:56:29 +0800 Subject: [PATCH] 封装选择部门组件 --- src/views/operate/car/myIndex/edit/law/index.vue | 72 +++++++++-------------------------- 1 files changed, 19 insertions(+), 53 deletions(-) diff --git a/src/views/operate/car/myIndex/edit/law/index.vue b/src/views/operate/car/myIndex/edit/law/index.vue index 2d89a18..2f42531 100644 --- a/src/views/operate/car/myIndex/edit/law/index.vue +++ b/src/views/operate/car/myIndex/edit/law/index.vue @@ -19,22 +19,10 @@ </el-form-item> <!-- 鎵�灞為儴闂� --> <el-form-item class="optionItems" label="鎵�灞為儴闂�:" prop="departId"> - <!-- <el-input v-model="car.depart" placeholder="璇峰~鍐欐墍灞為儴闂�"></el-input> --> - <el-select v-model="car.departName" placeholder="璇烽�夋嫨鎵�灞為儴闂�"> - <el-option value="1"> - <el-tree - ref="tree" - :check-strictly="true" - :data="departList" - :props="defaultProps" - show-checkbox - @check-change="handleCheck" - default-expand-all - node-key="id" - > - </el-tree> - </el-option> - </el-select> + <departTree + :depart="carDepart" + @selectDepart="selectDepart" + ></departTree> </el-form-item> <!-- 杞︿富濮撳悕 --> <el-form-item class="optionItem" label="杞︿富濮撳悕:" prop="ownerName"> @@ -71,7 +59,12 @@ </template> <script> import { validateCarNum, validatePhone, validateName } from "@/utils/validate"; +import departTree from "@/components/departTree/index.vue"; + export default { + components: { + departTree, + }, data() { const checkCarNum = (rule, value, callback) => { if (value) { @@ -134,6 +127,7 @@ departName: "", departId: 0, }, + carDepart: {}, createCarRules: { departId: [ { @@ -182,14 +176,15 @@ }; }, created() { - const { getDepartTree } = this; - // 鍒濆鍖栭儴闂ㄦ爲 - getDepartTree(); // 鍒濆鍖栨暟鎹� this.car = JSON.parse(JSON.stringify(this.info)); if (!this.car.departName) { this.car.departName = this.car.pdepartName; } + this.carDepart = { + departId: this.car.departId, + departName: this.car.departName, + }; }, methods: { // 淇敼鎵ф硶杞� @@ -222,41 +217,12 @@ } }); }, - // 閮ㄩ棬淇敼 - handleCheck(data, checked) { - this.car.departId = data.id; - this.car.departName = data.departName; - // 鑾峰彇褰撳墠閫夋嫨鐨刬d鍦ㄦ暟缁勪腑鐨勭储寮� - const indexs = this.selectOrg.orgsid.indexOf(data.id); - // 濡傛灉涓嶅瓨鍦ㄦ暟缁勪腑锛屽苟涓旀暟缁勪腑宸茬粡鏈変竴涓猧d骞朵笖checked涓簍rue鐨勬椂鍊欙紝浠h〃涓嶈兘鍐嶆閫夋嫨銆� - if (indexs < 0 && this.selectOrg.orgsid.length === 1 && checked) { - this.$message({ - message: "鍙兘閫夋嫨涓�涓儴闂紒", - type: "warning", - showClose: true, - }); - // 璁剧疆宸查�夋嫨鐨勮妭鐐逛负false 寰堥噸瑕� - this.$refs.tree.setChecked(data, false); - } else if (this.selectOrg.orgsid.length === 0 && checked) { - // 鍙戠幇鏁扮粍涓虹┖ 骞朵笖鏄凡閫夋嫨 - // 闃叉鏁扮粍鏈夊�硷紝棣栧厛娓呯┖锛屽啀push - this.selectOrg.orgsid = []; - this.selectOrg.orgsid.push(data.id); - } else if ( - indexs >= 0 && - this.selectOrg.orgsid.length === 1 && - !checked - ) { - // 鍐嶆鐩存帴杩涜璧嬪�间负绌烘搷浣� - this.selectOrg.orgsid = []; - this.car.departName = ""; + + selectDepart(depart) { + if (depart) { + this.car.departId = depart.departId; + this.car.departName = depart.departName; } - }, - // 鑾峰彇閮ㄩ棬鏍� - getDepartTree() { - this.$axios.get("/sccg/depart/tree").then((res) => { - this.departList = res.data; - }); }, }, props: ["info", "closeDialog"], -- Gitblit v1.8.0