|
@@ -0,0 +1,82 @@
|
|
|
+<template>
|
|
|
+ <div class="Cascader">
|
|
|
+ <el-cascader
|
|
|
+ :options="options"
|
|
|
+ :props="props"
|
|
|
+ @expand-change="$expandChange"
|
|
|
+ @change="$change"
|
|
|
+ style="width:335px;"
|
|
|
+ :placeholder="cascaderPlaceholder"
|
|
|
+ ></el-cascader>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { mapActions } from "vuex";
|
|
|
+/* 描述说明:
|
|
|
+options: 级联选择 树形数据
|
|
|
+props:配置项 (可看 https://element.eleme.cn/#/zh-CN/component/cascader )
|
|
|
+expandChange: 等于 expand-change 属性
|
|
|
+change: 等于 change 属性
|
|
|
+*/
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: "Cascader",
|
|
|
+ props: {
|
|
|
+ options: { type: Array },
|
|
|
+ props: { type: Object },
|
|
|
+ expandChange: {},
|
|
|
+ change: {}
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ cascaderPlaceholder: "请选择/不选择默认根级"
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {},
|
|
|
+ methods: {
|
|
|
+ ...mapActions(["fetch"]),
|
|
|
+ $expandChange(value) {
|
|
|
+ if (typeof this.expandChange == "function") {
|
|
|
+ this.expandChange(value);
|
|
|
+ }
|
|
|
+ this.cascaderPlaceholder = this.findAreaName(value);
|
|
|
+ console.log(this.props)
|
|
|
+ console.log(this.cascaderPlaceholder);
|
|
|
+ // inputValue presentText $children
|
|
|
+ this.$children[0].presentText= this.cascaderPlaceholder
|
|
|
+ },
|
|
|
+ $change(value) {
|
|
|
+ if (typeof this.change == "function") {
|
|
|
+ this.change(value);
|
|
|
+ }
|
|
|
+ console.log(value);
|
|
|
+ console.log(this.$children[0])
|
|
|
+ },
|
|
|
+
|
|
|
+ // 级联选择时 因组件限制 需拼接 名字字符串在级联选择器上显示
|
|
|
+ findAreaName(tree) {
|
|
|
+ let _this = this
|
|
|
+ let i = 0;
|
|
|
+ let tmpStr = "";
|
|
|
+ find(this.options);
|
|
|
+ function find(subTree) {
|
|
|
+ subTree.forEach(item => {
|
|
|
+ if (item.id == tree[i]) {
|
|
|
+ tmpStr += item.name + "/";
|
|
|
+ if (
|
|
|
+ i < tree.length &&
|
|
|
+ item[_this.props.children] &&
|
|
|
+ item[_this.props.children].length > 0
|
|
|
+ ) {
|
|
|
+ i++;
|
|
|
+ find(item[_this.props.children]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return tmpStr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|