yuang-framework-ui-pc
Version:
yuang-framework-ui-pc Library
122 lines (121 loc) • 4.66 kB
JavaScript
;
const vue = require("vue");
const message = require("../utils/message");
const OrganizationDialog = require("./components/organization-dialog");
const iconsVue = require("@element-plus/icons-vue");
const httpConfig = require("yuang-framework-ui-common/lib/config/httpConfig");
const applicationConfig = require("yuang-framework-ui-common/lib/config/applicationConfig");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...{ name: "YuUimsOrganizationDialog" },
__name: "index",
props: /* @__PURE__ */ vue.mergeModels({
param: { default: {} }
}, {
"modelValue": {},
"modelModifiers": {}
}),
emits: /* @__PURE__ */ vue.mergeModels(["change"], ["update:modelValue"]),
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const emit = __emit;
const modelValue = vue.useModel(__props, "modelValue");
const initList = vue.ref([]);
const inputValue = vue.ref("");
const isShowDialog = vue.ref(false);
const isInitSuccess = vue.ref(false);
const componentParam = vue.computed(() => ({
modelValue: modelValue.value,
isMultiple: true,
isShowInput: true,
...props.param,
initList: initList.value
}));
const init = async () => {
if (modelValue.value) {
if (!componentParam.value.isMultiple) {
if (modelValue.value != "0") {
let res = await httpConfig.http.get(`${applicationConfig.application.gatewayServerBaseUrl}/uims-api/admin/uims-organization/selectInfo`, { params: { id: modelValue.value } });
const info = res.data.data;
inputValue.value = info.name;
initList.value = [info];
}
} else {
let idList = modelValue.value.split("|").filter((item) => item.trim() !== "");
if (idList.length > 0) {
let res = await httpConfig.http.post(`${applicationConfig.application.gatewayServerBaseUrl}/uims-api/admin/uims-organization/selectInfoList`, idList);
const infoList = res.data.data;
let names = "";
for (let index in infoList) {
names += infoList[index].name + "、";
}
inputValue.value = names.substring(0, names.length - 1);
initList.value = infoList;
}
}
}
isInitSuccess.value = true;
};
const showDialog = () => {
isShowDialog.value = true;
};
const hideDialog = () => {
if (!isInitSuccess.value) {
message.EleMessage.warning("请等待初始化成功");
return;
}
isShowDialog.value = false;
};
const handleChange = (selections) => {
console.log("selections", selections);
modelValue.value = "";
inputValue.value = "";
if (selections.length > 0) {
if (!componentParam.value.isMultiple) {
modelValue.value = selections[0].id;
inputValue.value = selections[0].name;
} else {
let modelValueValue = "";
let inputValueValue = "";
for (let index in selections) {
modelValueValue += selections[index].id + "|";
inputValueValue += selections[index].name + "、";
}
modelValue.value = "|" + modelValueValue;
inputValue.value = inputValueValue.substring(0, inputValueValue.length - 1);
}
}
emit("change", selections);
hideDialog();
};
vue.watch(
() => componentParam.value.modelValue,
() => {
init();
},
{ immediate: true }
);
__expose({
showDialog
});
return (_ctx, _cache) => {
const _component_el_input = vue.resolveComponent("el-input");
return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
componentParam.value.isShowInput ? (vue.openBlock(), vue.createBlock(_component_el_input, {
key: 0,
modelValue: inputValue.value,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => inputValue.value = $event),
"suffix-icon": vue.unref(iconsVue.Select),
onClick: showDialog
}, null, 8, ["modelValue", "suffix-icon"])) : vue.createCommentVNode("", true),
isShowDialog.value ? (vue.openBlock(), vue.createBlock(OrganizationDialog, {
key: 1,
modelValue: isShowDialog.value,
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isShowDialog.value = $event),
param: componentParam.value,
onChange: handleChange
}, null, 8, ["modelValue", "param"])) : vue.createCommentVNode("", true)
], 64);
};
}
});
module.exports = _sfc_main;