|
@@ -1,5 +1,6 @@
|
|
|
<script>
|
|
|
import { REFER } from "./api/index";
|
|
|
+import deepCopy from "@gby/deep-copy";
|
|
|
export default {
|
|
|
name: "PopoverSelect",
|
|
|
props: {
|
|
@@ -92,6 +93,7 @@ export default {
|
|
|
},
|
|
|
data: [],
|
|
|
selectData: [],
|
|
|
+ lastSelectData: [],
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -108,23 +110,25 @@ export default {
|
|
|
watch: {
|
|
|
"$props.value": {
|
|
|
handler: function (newProp) {
|
|
|
- if (!newProp) this.selectData = [];
|
|
|
+ if (!newProp) this.lastSelectData = [];
|
|
|
},
|
|
|
immediate: true,
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
|
+ //
|
|
|
+ emitChange(prop) {
|
|
|
+ const { type, source, multiple } = this.$props;
|
|
|
+ this.$emit("change", multiple ? prop : prop[0], source, type);
|
|
|
+ },
|
|
|
// open dialog
|
|
|
async open() {
|
|
|
this.visible = true;
|
|
|
await this.useReset();
|
|
|
- console.log("open", this.selectData);
|
|
|
},
|
|
|
// hide dialog
|
|
|
async hide() {
|
|
|
this.visible = false;
|
|
|
- // this.$emit("input", []);
|
|
|
- console.log("hide", this.selectData);
|
|
|
},
|
|
|
// fetch list
|
|
|
async fetchList(prop, page) {
|
|
@@ -141,11 +145,12 @@ export default {
|
|
|
}
|
|
|
} catch (err) {
|
|
|
//
|
|
|
+ console.error(err);
|
|
|
} finally {
|
|
|
this.loading = false;
|
|
|
}
|
|
|
},
|
|
|
- // reset list
|
|
|
+ // reset
|
|
|
async useReset() {
|
|
|
const { type, source, queryParams } = this.$props;
|
|
|
this.model = {
|
|
@@ -156,53 +161,64 @@ export default {
|
|
|
};
|
|
|
await this.fetchList(this.model, this.page);
|
|
|
},
|
|
|
- // query list
|
|
|
+ // query
|
|
|
async useQuery() {
|
|
|
await this.fetchList(this.model, this.page);
|
|
|
},
|
|
|
+ // cancel
|
|
|
+ useCancel(prop) {
|
|
|
+ const { multiple } = this.$props;
|
|
|
+ this.useUpdate(multiple ? prop : prop[0]);
|
|
|
+ this.hide();
|
|
|
+ },
|
|
|
// confirm
|
|
|
- async useConfirm(prop) {
|
|
|
+ useConfirm(prop) {
|
|
|
const { multiple } = this.$props;
|
|
|
- await this.hide();
|
|
|
- await this.useUpdate(multiple ? prop : prop[0]);
|
|
|
+ this.useUpdate(multiple ? prop : prop[0]);
|
|
|
+ this.emitChange(this.selectData);
|
|
|
+ this.lastSelectData = deepCopy(this.selectData);
|
|
|
+ this.hide();
|
|
|
},
|
|
|
- // delete tag
|
|
|
+ // delete
|
|
|
useDelete(prop) {
|
|
|
this.selectData.splice(prop, 1);
|
|
|
this.useUpdate(this.selectData);
|
|
|
+ this.emitChange(this.selectData);
|
|
|
+ this.lastSelectData = deepCopy(this.selectData);
|
|
|
},
|
|
|
// update
|
|
|
useUpdate(prop) {
|
|
|
- const { source, multiple, valueKey, dataMapping, type } = this.$props;
|
|
|
- // update v-model
|
|
|
- const vModel = multiple
|
|
|
- ? prop.map((item) => item[valueKey])
|
|
|
- : prop[valueKey];
|
|
|
- this.$emit("input", vModel);
|
|
|
+ const { source, multiple, valueKey, dataMapping } = this.$props;
|
|
|
// update data mapping
|
|
|
- for (let key in dataMapping) {
|
|
|
- source[key] = prop[dataMapping[key]];
|
|
|
+ if (multiple) {
|
|
|
+ const vModel = prop.map((item) => item[valueKey]);
|
|
|
+ this.$emit("input", vModel);
|
|
|
+ } else {
|
|
|
+ const vModel = prop[valueKey];
|
|
|
+ this.$emit("input", vModel);
|
|
|
+ for (let key in dataMapping) {
|
|
|
+ source[key] = prop[dataMapping[key]];
|
|
|
+ }
|
|
|
+ this.$emit("update:source", source);
|
|
|
}
|
|
|
- this.$emit("update:source", source);
|
|
|
- // emit change
|
|
|
- this.$emit("change", prop, type, source);
|
|
|
},
|
|
|
// row click
|
|
|
- rowClick(prop) {
|
|
|
+ onceClick(prop) {
|
|
|
const { multiple } = this.$props;
|
|
|
// 单选
|
|
|
if (!multiple) this.$refs.multipleTable.clearSelection();
|
|
|
[prop].forEach((row) => this.$refs.multipleTable.toggleRowSelection(row));
|
|
|
},
|
|
|
// row double click
|
|
|
- // async rowDblclick(prop) {
|
|
|
- // const { multiple } = this.$props;
|
|
|
- // if (!multiple) await this.useConfirm([prop]);
|
|
|
- // },
|
|
|
+ doubleClick(prop) {
|
|
|
+ const { multiple } = this.$props;
|
|
|
+ if (!multiple) this.useConfirm([prop]);
|
|
|
+ },
|
|
|
// selection change
|
|
|
selectionChange(prop) {
|
|
|
- this.selectData = prop;
|
|
|
- console.log("selectionChange", prop);
|
|
|
+ if (prop && prop.length) {
|
|
|
+ this.selectData = prop;
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
created() {},
|
|
@@ -234,7 +250,6 @@ export default {
|
|
|
:close-on-click-modal="false"
|
|
|
:close-on-press-escape="false"
|
|
|
append-to-body
|
|
|
- @close="hide"
|
|
|
>
|
|
|
<el-form
|
|
|
v-loading="loading"
|
|
@@ -261,8 +276,8 @@ export default {
|
|
|
height="45vh"
|
|
|
highlight-current-row
|
|
|
style="width: 100%; margin-bottom: 20px"
|
|
|
- @row-click="rowClick"
|
|
|
- @row-dblclick="useConfirm([$event])"
|
|
|
+ @row-click="onceClick"
|
|
|
+ @row-dblclick="doubleClick"
|
|
|
@selection-change="selectionChange"
|
|
|
>
|
|
|
<el-table-column
|
|
@@ -301,7 +316,9 @@ export default {
|
|
|
/>
|
|
|
</el-form>
|
|
|
<div style="margin-top: 20px; text-align: right">
|
|
|
- <el-button :size="size" @click="hide"> 取 消 </el-button>
|
|
|
+ <el-button :size="size" @click="useCancel(lastSelectData)">
|
|
|
+ 取 消
|
|
|
+ </el-button>
|
|
|
<el-button :size="size" @click="useConfirm(selectData)">
|
|
|
确 定
|
|
|
</el-button>
|
|
@@ -317,7 +334,7 @@ export default {
|
|
|
overflow: hidden;
|
|
|
"
|
|
|
>
|
|
|
- <div v-if="multiple && selectData.length">
|
|
|
+ <div v-if="multiple && lastSelectData.length">
|
|
|
<el-popover
|
|
|
:offset="-10"
|
|
|
:width="width"
|
|
@@ -328,10 +345,10 @@ export default {
|
|
|
placement="bottom-start"
|
|
|
>
|
|
|
<el-tag slot="reference" :size="size" style="margin-right: 10px">
|
|
|
- + {{ selectData.length }}
|
|
|
+ + {{ lastSelectData.length }}
|
|
|
</el-tag>
|
|
|
<el-tag
|
|
|
- v-for="(tag, index) in selectData"
|
|
|
+ v-for="(tag, index) in lastSelectData"
|
|
|
:size="size"
|
|
|
hit
|
|
|
closable
|
|
@@ -339,7 +356,7 @@ export default {
|
|
|
display: 'flex',
|
|
|
justifyContent: 'space-between',
|
|
|
alignItems: 'center',
|
|
|
- margin: selectData.length - 1 === index ? '0' : '0 0 5px 0',
|
|
|
+ margin: lastSelectData.length - 1 === index ? '0' : '0 0 5px 0',
|
|
|
}"
|
|
|
@close="useDelete(index)"
|
|
|
>
|