// plugin/etc/components/pop-device/pop-device.js Component({ /** * 组件的属性列表 */ properties: { list: { type: Array, value: [], observer: function (newVal, oldVal) { let self = this; if (newVal) { self._handlerdataconversion(newVal); } } }, show: { type: Boolean, value: false, observer: function (newVal, oldVal) { let self = this; if (newVal) { self.configbeginSearch(newVal); } } }, btnText: { type: String, value: '确定激活' } }, /** * 组件的初始数据 */ data: { deviceList: [], hight: 20, device: "", beginSearch: false, isScrolly: false, iconOkPre: "/static/etc/signGetAuth/device-select.png", iconOkNor: "/static/etc/signGetAuth/device-no.png", }, /** * 组件的方法列表 */ methods: { configbeginSearch(newvalue) { this.setData({ beginSearch: newvalue }); }, _handlerdataconversion(newvalue) { let self = this; var leh = newvalue.length; var hg = 20; var scroll = false; if (leh < 4) { hg = 120 * leh; } else { hg = 120 * 4; scroll = true; } self.configselcetDevice(newvalue); self.setData({ deviceList: newvalue, hight: hg, isScrolly: scroll, }); }, /// 配置选中设备 configselcetDevice(array) { let device = ''; for (let index = 0; index < array.length; index++) { const element = array[index]; if (element.is_select) { device = element.device; break; } } this.setData({ device: device }) }, tapItem(e) { let device = e.currentTarget.dataset.item.device; let array = this.data.deviceList; for (let index = 0; index < array.length; index++) { const element = array[index]; if (element.device.name === device.name) { element.is_select = true; } else { element.is_select = false; } } this.setData({ device: device, deviceList: array }) }, confirmOwner() { let device = this.data.device; if (device) { this.setData({ beginSearch: false }) this.triggerEvent("OnOwner", device); } else { wx.showToast({ title: "请选择激活设备", icon: "none" }) } }, } })