|
[多端开发]
UIMultiSelector 组件怎么多次调用
[复制链接]
本帖最后由 BIP330889 于 2022-12-8 19:03 编辑
使用 UIMultiSelector 组件
- function getQueryBeech(id, str) {
- http({
- url: '/api/exhibition/query',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- },
- data: {
- values: {
- level: id
- }
- },
- isLoading: false
- }).then(function(res) {
- console.log(JSON.stringify(res), '999');
- data2 = res.result
- if (data2.length !== 0) {
- var dataItem = res.result.map(function(item) {
- return {
- text: item.name,
- value: item.code,
- }
- })
- let i = id
- let list = str
- selector.open({
- data: dataItem,
- text: '请选择展柜' + i
- }, function(ret) {
- const retVal = JSON.stringify(ret)
- console.log(retVal, 'rtttrtrt' );
- if (ret[0].isItems) {
- // 关闭组件
- selector.close()
- list.push(ret[0].value)
- i++
- // 重新开始
- getQueryBeech(i, list)
- } else {
- document.querySelector('#selectReason1').innerHTML = list.join('-')
- document.querySelector('#selectReason1').setAttribute('data-value', list.join('-'))
- selector.close()
- }
- })
- }
- })
- }
复制代码
封装的组件
- var UIMultiSelector = null
- selector.open = function (options, callback) {
- UIMultiSelector = api.require('UIMultiSelector');
- UIMultiSelector.open({
- rect: {
- h: 244
- },
- text: {
- title: options.text,
- leftBtn: '取消',
- rightBtn: '确认'
- },
- max: 0,
- singleSelection: true,
- styles: {
- mask: 'rgba(0,0,0,0.3)',
- title: {
- bg: '#eee',
- color: '#888',
- size: 14,
- h: 44
- },
- leftButton: {
- bg: '#46C0C1',
- size: 13,
- w: 70,
- h: 30,
- marginT: 5,
- marginL: 8,
- color: '#fff',
- cornerRadius: 6
- },
- rightButton: {
- bg: '#46C0C1',
- size: 13,
- w: 70,
- h: 30,
- marginT: 5,
- marginL: 8,
- color: '#fff',
- cornerRadius: 6
- },
- item: {
- h: 38,
- bg: '#fff',
- bgActive: '#fff',
- bgHighlight: '#f4f4f4',
- color: '#333333',
- active: '#46C0C1',
- highlight: '#46C0C1',
- size: 14,
- lineColor: '#ddd',
- textAlign: 'center'
- }
- },
- maskClose: false,
- animation: true,
- items: options.data
- }, function (ret, err) {
- if (ret) {
- if (ret.eventType === 'clickRight') {
- callback(ret.items)
- } else if (ret.eventType === 'clickLeft') {
- UIMultiSelector.close();
- } else if (ret.eventType === 'clickItem') {
- ret.items[0].isItems = true
- callback(ret.items)
- }
- }
- });
- }
- selector.close = function() {
- UIMultiSelector.close();
- }
复制代码
|
|