1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<template>
<div class="app-mob-mpicker">
<ion-input :disabled="disabled" :value="(curValue.length > 0 ? 'hasValue' : '')" readonly @click="openView" @ionFocus="enter" @ionBlur="leave">
<div class="app-mob-mpicker__text" >
<template v-for="(item,index) in curValue">
{{item.srfmajortext}}
<span v-if="index < curValue.length-1" :key="index">,</span>
</template>
</div>
</ion-input>
<app-mob-icon class="right-common-icon" v-if="!(curValue.length > 0)" name="search-outline" @onClick="openView"></app-mob-icon>
<app-mob-icon v-else class="right-common-icon" name="close-circle-outline" @onClick="onClear"></app-mob-icon>
</div>
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { Subject } from "rxjs";
import { ViewOpenService } from "ibiz-vue";
import { ViewTool } from "ibiz-core";
@Component({})
export default class AppMobMpicker extends Vue {
/**
* 表单数据
*
* @type {*}
* @memberof AppMobMpicker
*/
@Prop() public data!: any;
/**
* 是否启用
*
* @type {boolean}
* @memberof AppMobMpicker
*/
@Prop({default:false}) public disabled?: boolean;
/**
* 应用实体主键属性名称
*
* @type {string}
* @memberof AppPicker
*/
@Prop({ default: 'srfkey' }) public deKeyField!: string;
/**
* 值
*
* @type {*}
* @memberof AppMobMpicker
*/
@Prop() public value?: any;
/**
* 属性项名称
*
* @type {string}
* @memberof AppMobMpicker
*/
@Prop() public name!: string;
/**
* 视图上下文
*
* @type {*}
* @memberof AppMobMpicker
*/
@Prop() public context!: any;
/**
* 视图参数
*
* @type {*}
* @memberof AppMobMpicker
*/
@Prop() public viewparams!: any;
/**
* 视图参数(如:视图name,title,width,height)
*
* @type {*}
* @memberof AppMobMpicker
*/
@Prop() public pickupView?: any;
/**
* 导航参数
*
* @type {*}
* @memberof AppSelect
*/
@Prop() protected navigateParam?: any;
/**
* 导航上下文
*
* @type {*}
* @memberof AppSelect
*/
@Prop() protected navigateContext?: any;
/**
* 视图打开服务
*
* @type {ViewOpenService}
* @memberof AppPicker
*/
public openService: ViewOpenService = ViewOpenService.getInstance();
/**
* 源数组
* @type {any[]}
* @memberof AppMobMpicker
*/
public items: any[] = [];
/**
* 值
*
* @type {*}
* @memberof AppMobMpicker
*/
get curValue() {
if (this.value) {
return JSON.parse(this.value);
}
return [];
}
/**
* 打开视图
*/
public async openView($event: any) {
if (this.disabled) {
return;
}
// 公共参数处理
let data: any = {};
const bcancel: boolean = this.handlePublicParams(data);
if (!bcancel) {
return;
}
// 参数处理
const view = { ...this.pickupView };
let _context = data.context;
let _param = data.param;
let select:any = []
this.curValue.forEach((temp:any) => {
select.push({srfmajortext:temp.text,srfkey:temp.value})
});
_param = Object.assign(_param,{ selectedData: [...select]});
// 判断打开方式
if(!view.viewModelData?.codeName){
this.$Notice.error(this.$t('app.commonWords.notFoundPickerView'));
return;
}
const openMode = view.viewModelData.openMode;
if(openMode && openMode.indexOf('DRAWER') != -1){
this.openDrawer(view, _context, _param);
} else if(openMode === 'POPOVER'){
this.openPopOver(view, _context, _param);
}else{
this.openPopupModal(view, _context, _param);
}
}
/**
* 模态模式打开视图
*
* @private
* @param {*} view
* @param {*} data
* @memberof AppMobMpicker
*/
private async openPopupModal(view: any, context: any, param: any): Promise<any> {
const result: any = await this.openService.openModal(view, context, param);
if (result || Object.is(result.ret, 'OK')) {
this.openViewClose(result);
}
}
/**
* 抽屉模式打开视图
*
* @private
* @param {*} view
* @param {*} data
* @memberof AppMobMpicker
*/
private async openDrawer(view: any, context: any, param: any): Promise<any> {
let container: Subject<any> = await this.openService.openDrawer(
view,
context,
param
);
container.subscribe((result: any) => {
if (!result || !Object.is(result.ret, "OK")) {
return;
}
this.openViewClose(result);
});
}
/**
* 气泡模式打开视图
*
* @private
* @param {*} view
* @param {*} data
* @memberof AppPicker
*/
private async openPopOver(view: any, context: any, param: any,customParam?:any): Promise<any> {
let result: any = await this.openService.openPopOver(view, context, param,customParam);
if (result || Object.is(result.ret, 'OK')) {
this.openViewClose(result);
}
}
/**
* 公共参数处理
*
* @param {*} arg
* @returns
* @memberof AppMobMpicker
*/
public handlePublicParams(arg: any): boolean {
if (!this.data) {
return false;
}
// 导航参数处理
const {context, param} = ViewTool.formatNavigateParam( this.navigateContext, this.navigateParam, this.context, this.viewparams, this.data );
arg.context = context;
arg.param = param;
return true;
}
/**
* 打开页面关闭
*
* @param {*} result
* @memberof AppMobMpicker
*/
public openViewClose(result: any) {
let datas: any = [];
let valueDatas: any = [];
if (result.datas && Array.isArray(result.datas)) {
result.datas.forEach((data: any) => {
datas.push({ srfmajortext: data.srfmajortext, srfkey: data.srfkey });
});
}
if (this.name) {
this.$emit("formitemvaluechange", {
name: this.name,
value: datas.length > 0 ? JSON.stringify(datas) : null,
event: {}
});
}
}
/**
* 清除
*/
public onClear($event: any): void {
if (this.name) {
this.$emit('formitemvaluechange', { name: this.name, value: '', event:{} });
}
}
/**
* 有焦点时事件
*
* @memberof AppMobMpicker
*/
public enter(e: any) {
this.$emit('enter', {name: this.name, value: this.value, event:e});
}
/**
* 失去焦点事件
*
* @memberof AppMobMpicker
*/
public leave(e: any) {
this.$emit('leave', {name: this.name, value: this.value, event:e});
}
}
</script>