帖子
帖子
用户
博客
课程
显示全部楼层
1
帖子
0
勋章
11
Y币

[多端开发] UIMultiSelector 组件怎么多次调用

[复制链接]
发表于 2022-12-8 17:29:39
本帖最后由 BIP330889 于 2022-12-8 19:03 编辑

使用 UIMultiSelector 组件

  1. function getQueryBeech(id, str) {
  2.     http({
  3.       url: '/api/exhibition/query',
  4.       headers: {
  5.         'Content-Type': 'application/x-www-form-urlencoded'
  6.       },
  7.       data: {
  8.         values: {
  9.           level: id
  10.         }
  11.       },
  12.       isLoading: false
  13.     }).then(function(res) {
  14.       console.log(JSON.stringify(res), '999');
  15.       data2 = res.result
  16.       if (data2.length !== 0) {
  17.         var dataItem = res.result.map(function(item) {
  18.           return {
  19.             text: item.name,
  20.             value: item.code,
  21.           }
  22.         })
  23.         let i = id
  24.         let list = str
  25.         selector.open({
  26.           data: dataItem,
  27.           text: '请选择展柜' + i
  28.         }, function(ret) {
  29.           const retVal = JSON.stringify(ret)
  30.           console.log(retVal, 'rtttrtrt' );
  31.           if (ret[0].isItems) {
  32.             // 关闭组件
  33.             selector.close()
  34.             list.push(ret[0].value)
  35.             i++
  36.             // 重新开始
  37.             getQueryBeech(i, list)
  38.           } else {
  39.             document.querySelector('#selectReason1').innerHTML = list.join('-')
  40.             document.querySelector('#selectReason1').setAttribute('data-value', list.join('-'))
  41.             selector.close()
  42.           }
  43.         })
  44.       }
  45.     })
  46.   }
复制代码




封装的组件


  1. var UIMultiSelector = null
  2. selector.open = function (options, callback) {
  3.   UIMultiSelector = api.require('UIMultiSelector');
  4.   UIMultiSelector.open({
  5.     rect: {
  6.       h: 244
  7.     },
  8.     text: {
  9.       title: options.text,
  10.       leftBtn: '取消',
  11.       rightBtn: '确认'
  12.     },
  13.     max: 0,
  14.     singleSelection: true,
  15.     styles: {
  16.       mask: 'rgba(0,0,0,0.3)',
  17.       title: {
  18.         bg: '#eee',
  19.         color: '#888',
  20.         size: 14,
  21.         h: 44
  22.       },
  23.       leftButton: {
  24.         bg: '#46C0C1',
  25.         size: 13,
  26.         w: 70,
  27.         h: 30,
  28.         marginT: 5,
  29.         marginL: 8,
  30.         color: '#fff',
  31.         cornerRadius: 6
  32.       },
  33.       rightButton: {
  34.         bg: '#46C0C1',
  35.         size: 13,
  36.         w: 70,
  37.         h: 30,
  38.         marginT: 5,
  39.         marginL: 8,
  40.         color: '#fff',
  41.         cornerRadius: 6
  42.       },
  43.       item: {
  44.         h: 38,
  45.         bg: '#fff',
  46.         bgActive: '#fff',
  47.         bgHighlight: '#f4f4f4',
  48.         color: '#333333',
  49.         active: '#46C0C1',
  50.         highlight: '#46C0C1',
  51.         size: 14,
  52.         lineColor: '#ddd',
  53.         textAlign: 'center'
  54.       }
  55.     },
  56.     maskClose: false,
  57.     animation: true,
  58.     items: options.data
  59.   }, function (ret, err) {
  60.     if (ret) {
  61.       if (ret.eventType === 'clickRight') {
  62.         callback(ret.items)
  63.       } else if (ret.eventType === 'clickLeft') {
  64.         UIMultiSelector.close();
  65.       } else if (ret.eventType === 'clickItem') {
  66.         ret.items[0].isItems = true
  67.         callback(ret.items)
  68.       }
  69.     }
  70.   });
  71. }
  72. selector.close = function() {
  73.   UIMultiSelector.close();
  74. }
复制代码

一次只能打开一个吧  关掉后才能打开另一个
1
帖子
0
勋章
11
Y币
勇可可 · 2022-12-8 18:24一次只能打开一个吧  关掉后才能打开另一个

调用关闭的方法了,第一段代码的地28行
1
帖子
0
勋章
11
Y币
勇可可 · 2022-12-8 18:24一次只能打开一个吧  关掉后才能打开另一个

调用关闭的方法了,第一段代码的地28行
BIP330889 · 2022-12-9 08:53调用关闭的方法了,第一段代码的地28行

打开第2次 不能打开吗 还是说报错之类的
1
帖子
0
勋章
11
Y币
勇可可 · 2022-12-9 10:52打开第2次 不能打开吗 还是说报错之类的

第二次可以打开,也没报错,打开前打印的数据和页面显示的数据不一样,显示还是第一次的数据
现在解决了没,如果没解决看到后重新发个帖子
您需要登录后才可以回帖 登录

本版积分规则