<template>
|
<view class="uni-page-modal-small-wnd-ref-ext-button">
|
<view class="uni-panel-ext-button">
|
<input class="uni-panel-input" type="text" v-model="visible" :disabled="disabled" @on-blur="onChange" />
|
<view class="uni-panel-right-ico">
|
<a @click="onClick"><i class="ace-icon fa fa-plus-circle"></i></a>
|
</view>
|
</view>
|
</view>
|
</template>
|
<script>
|
import {
|
Base64
|
} from "js-base64";
|
import lua from "@/lua";
|
import {
|
showError
|
} from "@/libs/util";
|
import {
|
runCustomEvent,
|
} from "@/api/data.js"
|
|
export default {
|
name: "OIDataSmallDialogRefExtButton",
|
components: {
|
|
},
|
props: {
|
clsId: String,
|
icon: String,
|
action: String,
|
beforeClickEvent: String,
|
callbackEvent: String,
|
enviroment: Object,
|
objAttr: Object,
|
modelValue: String,
|
form: Object,
|
disabled: Boolean,
|
},
|
data() {
|
return {
|
openDataQueryDlg: {
|
visible: false,
|
title: "",
|
param: {},
|
},
|
openSelectUserDlg: {
|
visible: false,
|
title: "",
|
subTitle: "",
|
orgShowDept: false,
|
orgShowUser: true,
|
orgShowRole: false,
|
showOrgTab: true,
|
showUserTab: true,
|
multi: false,
|
},
|
openCommonDlg: {
|
visible: false,
|
param: {},
|
},
|
};
|
},
|
computed: {
|
visible: {
|
get() {
|
return this.modelValue;
|
},
|
set(value) {
|
this.$emit("update:modelValue", value);
|
},
|
},
|
actionId() {
|
let id = this.action;
|
if (!id) return "";
|
if (id[0] != "{" && id[id.length - 1] != "}") id = `{${id}}`;
|
return id;
|
},
|
beforeClickEventId() {
|
let id = this.beforeClickEvent;
|
if (!id) return "";
|
if (id[0] != "{" && id[id.length - 1] != "}") id = `{${id}}`;
|
return id;
|
},
|
callbackEventId() {
|
let id = this.callbackEvent;
|
if (!id) return "";
|
if (id[0] != "{" && id[id.length - 1] != "}") id = `{${id}}`;
|
return id;
|
},
|
},
|
methods: {
|
setData(obj) {
|
let that = this;
|
let keys = [];
|
let val, data;
|
|
Object.keys(obj).forEach(function(key) {
|
keys = key.split(".");
|
val = obj[key];
|
data = that.$data;
|
keys.forEach(function(key2, index) {
|
if (index + 1 == keys.length) {
|
that.$set(data, key2, val);
|
} else {
|
if (!data[key2]) {
|
that.$set(data, key2, {});
|
}
|
}
|
data = data[key2];
|
});
|
});
|
},
|
|
async onClick() {
|
try {
|
if (!this.beforeClickEventId)
|
return this.$Message.warning("未指定“点击按钮前”事件");
|
if (!this.callbackEventId)
|
return this.$Message.warning("未指定“按钮回调”事件");
|
this.dataObjRunCustomEvent_Return();
|
|
} catch (ex) {
|
this.showError(ex);
|
}
|
},
|
async onClicked({
|
inputParameter = {},
|
dataJson = []
|
}) {
|
try {
|
let extInfo = {
|
...this.enviroment,
|
edit_dlg: {
|
type: "small",
|
class_id: this.clsId,
|
},
|
};
|
if (typeof inputParameter == "object")
|
inputParameter = JSON.stringify(inputParameter);
|
await lua(
|
this,
|
await runCustomEvent({
|
ed_type: 0,
|
class_id: this.clsId,
|
event_id: this.callbackEventId,
|
obj_attr: this.objAttr,
|
ext_info: Base64.encode(JSON.stringify(extInfo)),
|
data_json: Base64.encode(JSON.stringify(dataJson)),
|
input_param: Base64.encode(inputParameter),
|
})
|
);
|
} catch (ex) {
|
this.showError(ex);
|
}
|
},
|
dataObjRunCustomEvent(info, data_attr) {
|
var $this = this;
|
let extInfo = {
|
...this.enviroment,
|
edit_dlg: {
|
type: "small",
|
class_id: this.clsId,
|
},
|
};
|
|
var global_attr = Base64.encode(JSON.stringify({})); //将字符串转换为bas}e64编码
|
if (info.dataJson)
|
info.dataJson = Base64.encode(JSON.stringify(info.dataJson)); //将字符串转换为base64编码
|
var obj_attr = {};
|
info.attr.forEach(item => {
|
obj_attr[item.attr] = item.val;
|
});
|
extinfo = Base64.encode(JSON.stringify(extinfo)); //将字符串转换为base64编码
|
var dataInfo = {
|
ed_type: info.edtype,
|
start_transaction: '',
|
class_id: info.clsid,
|
class_name: '',
|
event_id: info.eventid,
|
event_name: '',
|
data_obj_id: info.objid,
|
obj_attr: obj_attr,
|
prj_id: info.projectid,
|
ref_cls_id: info.rclsid,
|
rel_obj_id: info.robjid,
|
user_login: info.userlogin,
|
data_json: info.dataJson,
|
compose_info: '',
|
ext_info: extinfo,
|
global_attr: global_attr,
|
input_param: '',
|
};
|
console.log(dataInfo);
|
// return;
|
runCustomEvent(dataInfo).then(data => {
|
console.log(data);
|
if (data.ret != 0) {
|
var tip = data.err_info ? typeof data.err_info == 'string' ? data.err_info :
|
data
|
.err_info.join('<br/>') : '';
|
if (data.ret == 801) uni.showModal({
|
title: this.translateSys('tip'),
|
content: tip,
|
showCancel: false,
|
confirmText: this.translateSys('cancel')
|
});
|
else uni.showModal({
|
title: this.translateSys('tip'),
|
content: tip + ',提示:' + data.ret,
|
showCancel: false,
|
confirmText: this.translateSys('cancel')
|
});
|
return false
|
} else {
|
var tip = data.info ? typeof data.info == 'string' ? data.info : data.info
|
.join(
|
'<br/>') : '';
|
if (tip) uni.showModal({
|
title: this.translateSys('tip'),
|
content: tip,
|
showCancel: false,
|
confirmText: this.translateSys('cancel')
|
});
|
|
var actionlist = data.action;
|
if (actionlist) {
|
console.log(actionlist);
|
for (var i = 0; i < actionlist.length; i++) {
|
var action = actionlist[i];
|
if (action.action_type == 'set_dlg_attr') {
|
var result = action.value;
|
for (var i = 0; i < result.length; i++) {
|
if (result[i].choice_list) {
|
for (var c = 0; c < $this.$data.classAttrList
|
.length; c++) {
|
var attr = $this.$data.classAttrList[c].Attr;
|
for (var j = 0; j < attr.length; j++) {
|
if (attr[j].Name == result[i].attr) {
|
if (utils.classUtils.attrTypeIsDict(attr[j]
|
.Type)) {
|
var dictItemList = [];
|
for (var d in result[i].choice_list) {
|
var val = result[i].choice_list[d];
|
dictItemList.push({
|
"CN_S_NAME": val,
|
"Name": val,
|
"label": val,
|
"value": val
|
});
|
}
|
attr[j].dictitem = dictItemList;
|
// attr[j].dictitem = result[i].choice_list;
|
}
|
}
|
}
|
}
|
}
|
for (var c = 0; c < $this.$data.classAttrList.length; c++) {
|
var attr = $this.$data.classAttrList[c].Attr;
|
for (var j = 0; j < attr.length; j++) {
|
console.log(attr[j].Name + '==' + result[i].attr);
|
if (attr[j].Name == result[i].attr) {
|
attr[j].Value = result[i].value;
|
}
|
}
|
}
|
var length = 0;
|
if (!$this.$data.refdatastore.filter(function(s) {
|
return result[i].attr == s.attr
|
}).length) {
|
length = 1;
|
$this.$data.refdatastore.push(result[i]);
|
}
|
if (length == 0) {
|
for (var j = 0; j < $this.$data.refdatastore.length; j++) {
|
if ($this.$data.refdatastore[j].attr == result[i]
|
.attr) {
|
$this.$data.refdatastore[j].value = result[i]
|
.value;
|
}
|
}
|
}
|
}
|
} else if (data.action[i].action_type == 'set_global_attr') {
|
$this.$data.global_attr = data.action[i].value || [];
|
}
|
}
|
}
|
|
if (data.result) {
|
var result = data.result;
|
for (var i = 0; i < result.length; i++) {
|
for (var c = 0; c < $this.$data.classAttrList.length; c++) {
|
var attr = $this.$data.classAttrList[c].Attr;
|
for (var j = 0; j < attr.length; j++) {
|
if (attr[j].Name == result[i].attr) {
|
attr[j].Value = result[i].value;
|
}
|
}
|
}
|
|
var length = 0;
|
if (!$this.$data.refdatastore.filter(function(s) {
|
return result[i].attr == s.attr
|
}).length) {
|
length = 1;
|
$this.$data.refdatastore.push(result[i]);
|
}
|
if (length == 0) {
|
for (var j = 0; j < $this.$data.refdatastore.length; j++) {
|
if ($this.$data.refdatastore[j].attr == result[i].attr) {
|
$this.$data.refdatastore[j].value = result[i].value;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
}).catch(ex => {
|
// console.log(ex);
|
uni.showModal({
|
title: this.translateSys('error') + " 3.1",
|
content: ex.errMsg,
|
showCancel: false,
|
confirmText: this.translateSys('cancel')
|
});
|
});
|
},
|
|
dataObjRunCustomEvent_Return() {
|
let extInfo = {
|
...this.enviroment,
|
edit_dlg: {
|
type: "small",
|
class_id: this.clsId,
|
},
|
};
|
extinfo = Base64.encode(JSON.stringify(extinfo)); //将字符串转换为base64编码
|
var global_attr = Base64.encode(JSON.stringify({})); //将字符串转换为base64编码
|
var dataInfo = {
|
ed_type: "0",
|
class_id: this.clsId,
|
event_id: this.beforeClickEventId,
|
obj_attr: this.objAttr,
|
ext_info: extinfo,
|
global_attr: global_attr,
|
};
|
console.log(dataInfo);
|
// return;
|
runCustomEvent(dataInfo).then(data => {
|
console.log(data);
|
if (data.ret != 0) {
|
var tip = data.err_info ? typeof data.err_info == 'string' ? data.err_info :
|
data
|
.err_info.join('<br/>') : '';
|
if (data.ret == 801) uni.showModal({
|
title: this.translateSys('tip'),
|
content: tip,
|
showCancel: false,
|
confirmText: this.translateSys('cancel')
|
});
|
else uni.showModal({
|
title: this.translateSys('tip'),
|
content: tip + ',提示:' + data.ret,
|
showCancel: false,
|
confirmText: this.translateSys('cancel')
|
});
|
return false
|
} else {
|
var tip = data.info ? typeof data.info == 'string' ? data.info : data.info
|
.join(
|
'<br/>') : '';
|
if (tip) uni.showModal({
|
title: this.translateSys('tip'),
|
content: tip,
|
showCancel: false,
|
confirmText: this.translateSys('cancel')
|
});
|
|
if (data != "") {
|
var actions = data.action;
|
console.log(actions);
|
if (actions) {
|
for (var i = 0; i < actions.length; i++) {
|
var action = actions[i];
|
var val = action.value;
|
var enviroment = JSON.stringify(enviroment);
|
|
if (action.action_type == 'open_panel') {
|
|
uni.showModal({
|
title: this.translateSys('tip'),
|
content: action.action_type + '此action尚未处理!'
|
showCancel: false,
|
confirmText: this.translateSys('close')
|
})
|
|
} else if (action.action_type == 'open_select_userdlg') {
|
var style = val.style;
|
var $this = this;
|
var param = {
|
button_callback: ,
|
req: req,
|
data_attr: data_attr
|
}
|
uni.navigateTo({
|
url: '../selpsn/index?mulit=false¶m=' + JSON
|
.stringify(
|
param),
|
events: {
|
AddPer(data, param) {
|
console.log(data, param);
|
let inputParameter = data;
|
this.onClicked({
|
inputParameter
|
});
|
}
|
}
|
});
|
} else if (action.action_type == 'open_data_query_dlg') {
|
uni.showModal({
|
title: this.translateSys('tip'),
|
content: action.action_type + '此action尚未处理!'
|
showCancel: false,
|
confirmText: this.translateSys('close')
|
})
|
} else if (action.action_type == 'open_common_dlg') {
|
var $this = this;
|
if (val.common_dlg_id == 'check_list') {
|
$this.$data.check_list = val.config;
|
if (val.config.appear_style == 'sideslip') //判断是否是侧滑
|
$this.$data.popupType = 'right';
|
else
|
$this.$data.popupType = 'center'
|
// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
|
$this.$refs.popup.open($this.$data.popupType);
|
var popupParam = {
|
index: index,
|
iindex: iindex,
|
button_callback: button_callback,
|
req: req,
|
data_attr: data_attr
|
}
|
$this.$data.popupParam = popupParam;
|
}
|
} else if (action.action_type == 'open_project_query_dlg') {
|
var priRel = '-1';
|
if (action.value.select_range == '全部相关')
|
priRel = '0';
|
else if (action.value.select_range == '我负责的项目')
|
priRel = '1';
|
else if (action.value.select_range == '我创建的')
|
priRel = '2';
|
else if (action.value.select_range == '我参与的' || action.value
|
.select_range == '我参加的')
|
priRel = '3';
|
else if (action.value.select_range == '我关注的')
|
priRel = '4';
|
else if (action.value.select_range == '我下属的项目')
|
priRel = '5';
|
|
var $this = this;
|
var param_ = {
|
index: index,
|
iindex: iindex,
|
button_callback: button_callback,
|
req: req
|
}
|
uni.navigateTo({
|
url: '../selPrj/index?relation=' + priRel +
|
'¶m=' +
|
JSON.stringify(param_),
|
events: {
|
AddPer(data, param) {
|
$this.$data.classAttrList[param.index]
|
.Attr[param
|
.iindex].Value = data[0].Name;
|
$this.$data.classAttrList[param.index]
|
.Attr[param
|
.iindex].ValID = data[0].ID + ';' +
|
data[0]
|
.Name;
|
var callback_eventid = param
|
.button_callback
|
.trim();
|
if ($this.callbackEventId) {
|
var info = {
|
eventid: $this.callbackEventId,
|
edtype: "2",
|
projectid: data[0].ID,
|
rclsid: "",
|
robjid: "",
|
userlogin: "",
|
clsid: $this.clsId,
|
objid: "",
|
attr: param.req,
|
dataJson: [],
|
}
|
|
$this.DataObjRunCustomEvent(info);
|
}
|
}
|
}
|
});
|
} else {
|
var d = dialog({
|
title: '<i class="ace-icon fa fa-info-circle"></i> ' +
|
this.translateSys('tip'),
|
content: action.action_type + '此action尚未处理!'
|
});
|
d.show();
|
}
|
}
|
}
|
} else {
|
uni.showModal({
|
title: this.translateSys('tip') + "5.2",
|
content: '调用 before_click_button 脚本返回空,event_id' + eventid,
|
showCancel: false,
|
confirmText: this.translateSys('cancel')
|
});
|
}
|
}
|
|
}).catch(ex => {
|
// console.log(ex);
|
uni.showModal({
|
title: this.translateSys('tip') + "5.1",
|
content: ex.errMsg,
|
showCancel: false,
|
confirmText: this.translateSys('cancel')
|
});
|
});
|
},
|
|
async onChange() {
|
try {
|
if (!this.actionId) return;
|
let extInfo = {
|
...this.enviroment,
|
};
|
await lua(
|
this,
|
await runCustomEvent({
|
ed_type: 0,
|
class_id: this.clsId,
|
event_id: this.actionId,
|
obj_attr: this.objAttr,
|
ext_info: Base64.encode(JSON.stringify(extInfo)),
|
})
|
);
|
} catch (ex) {
|
this.showError(ex);
|
}
|
},
|
async onOpenDataQueryDlgOK(data) {
|
if (!data) throw new Error("未获取到选中数据");
|
let dataJson = [];
|
if (data instanceof Array) {
|
// 多选
|
data.forEach((d) => {
|
let id = d.id;
|
let attrs = [];
|
Object.keys(d).forEach((attr) => {
|
let value = (d[attr] || "").replace(/ /g, " ");
|
attrs.push({
|
attr,
|
value
|
});
|
});
|
dataJson.push({
|
id,
|
attrs
|
});
|
});
|
} else if (data instanceof Object) {
|
// 单选
|
let id = data.id;
|
let attrs = [];
|
Object.keys(data).forEach((attr) => {
|
let value = (data[attr] || "").replace(/ /g, " ");
|
attrs.push({
|
attr,
|
value
|
});
|
});
|
// dataJson.push({ id, attrs });
|
dataJson = {
|
id,
|
attrs
|
};
|
}
|
this.onClicked({
|
dataJson
|
});
|
},
|
onOpenSelectUserDlgOK(list) {
|
let inputParameter = "";
|
let datas = [];
|
list.forEach((l) => {
|
datas.push({
|
id: l.id,
|
name: l.name,
|
type: l.type,
|
});
|
});
|
inputParameter = datas;
|
this.onClicked({
|
inputParameter
|
});
|
},
|
onOpenCommonDlgOK(datas) {
|
let inputParameter = "";
|
if (typeof datas == "string") inputParameter = datas;
|
else inputParameter = JSON.stringify(datas);
|
this.onClicked({
|
inputParameter
|
});
|
},
|
setFormValues(attrs) {
|
this.refSmallDialog.setFormValues(attrs);
|
},
|
hideFormItems(attrs) {
|
this.refSmallDialog.hideFormItems(attrs);
|
},
|
setFormAllValues(attrs) {
|
this.$emit("on-set-all-value", attrs);
|
},
|
showError(ex) {
|
showError(this, ex);
|
},
|
},
|
setup() {
|
|
},
|
};
|
</script>
|
|
<style lang="less">
|
.uni-page-modal-small-wnd-ref-ext-button {
|
.uni-panel-input-content {
|
display: flex;
|
flex-direction: row;
|
width: 100%;
|
|
.uni-panel-input {
|
flex: 1;
|
}
|
|
.uni-panel-right-ico {
|
padding: 5rpx;
|
margin: 5rpx;
|
}
|
}
|
}
|
</style>
|