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O,uBAAP,OAAO,CAAE,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;iBACtC;YACH,CAAC;YACD,gBAAgB;YAChB,kBAAkB;gBAChB,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC;gBAC7D,IAAI,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE;oBACpC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;wBACrB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;oBAC7B,CAAC,CAAC,CAAC;iBACJ;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CAAA,CAAA;AA3KoB,aAAa;IADjC,WAAW,EAAE;GACO,aAAa,CA2KjC;eA3KoB,aAAa","file":"checkbox-group.js","sourcesContent":["import { SuperComponent, wxComponent } from '../common/src/index';\nimport config from '../common/config';\nimport Props from '../checkbox/checkbox-group-props';\n\nconst { prefix } = config;\nconst name = `${prefix}-checkbox-group`;\n@wxComponent()\nexport default class CheckBoxGroup extends SuperComponent {\n externalClasses = ['t-class'];\n\n relations = {\n '../checkbox/checkbox': {\n type: 'descendant' as 'descendant',\n linked() {\n this.updateChildren();\n },\n },\n };\n\n data = {\n classPrefix: name,\n checkboxOptions: [],\n };\n\n properties = {\n ...Props,\n defaultValue: {\n type: null,\n value: undefined,\n },\n };\n\n observers = {\n value: function () {\n this.updateChildren();\n },\n };\n\n lifetimes = {\n attached() {\n this.handleCreateMulCheckbox();\n },\n };\n\n controlledProps = [\n {\n key: 'value',\n event: 'change',\n },\n ];\n\n methods = {\n getChilds() {\n let items = this.getRelationNodes('../checkbox/checkbox');\n if (!items.length) {\n items = this.selectAllComponents('.t-checkbox-option');\n }\n return items || [];\n },\n\n // slot插入选项\n updateChildren() {\n const items = this.getChilds();\n\n const { value, disabled } = this.data;\n if (items.length > 0) {\n items.forEach((item: any) => {\n !item.data.checkAll &&\n item.setData({\n checked: value?.indexOf(item.data.value) > -1,\n });\n item.setDisabled(disabled);\n });\n // 关联可全选项\n if (items.findIndex((item) => item.data.checkAll) > -1) {\n items.forEach((item) => {\n item.setOptionLinked(true);\n });\n this.handleHalfCheck(items.length);\n }\n }\n },\n updateValue({ name, checked }) {\n const { value, max } = this.data;\n let newValue = value;\n if (max && checked && newValue.length === max) {\n return;\n }\n if (checked) {\n newValue = newValue.concat(name);\n } else {\n const index = newValue.findIndex((v: string) => v === name);\n newValue.splice(index, 1);\n }\n this._trigger('change', { value: newValue });\n },\n // 支持自定义options\n handleCreateMulCheckbox() {\n const { options } = this.data;\n // 数字数组|字符串数组|对像数组\n if (!options?.length || !Array.isArray(options)) {\n return;\n }\n const optionsValue = [];\n try {\n options.forEach((element) => {\n const typeName = typeof element;\n if (typeName === 'number' || typeName === 'string') {\n optionsValue.push({\n label: `${element}`,\n value: element,\n });\n } else if (typeName === 'object') {\n optionsValue.push({\n ...element,\n });\n }\n });\n this.setData({\n checkboxOptions: optionsValue,\n });\n this.updateChildren();\n } catch (error) {\n console.error('error', error);\n }\n },\n // 处理全选\n handleCheckAll(e) {\n const { checked, option, name } = e.detail || e;\n const items = this.getChilds();\n\n if (!option) {\n if (!items?.length) {\n return;\n }\n this._trigger('change', {\n value: items\n .map((item) => {\n if (item.data.disabled) {\n return this.data.value.includes(item.data.value) ? item.data.value : '';\n }\n return checked && !item.data.checkAll ? item.data.value : '';\n })\n .filter((val) => val),\n });\n } else {\n this.updateValue({ name, checked });\n }\n },\n // 处理options半选\n handleHalfCheck(len: number) {\n const items = this.getChilds();\n const checkboxOptions = items.filter((i) => !i.data.checkAll);\n const all = checkboxOptions.map((item) => item.data.value);\n const enableValue = checkboxOptions\n .filter((i) => !i.data.disabled)\n .map((item) => item.data.value);\n const currentVal = Array.from(new Set(this.data.value?.filter((i) => all.indexOf(i) > -1)));\n const element = items.find((item) => item.data.checkAll);\n if (currentVal.length) {\n element?.setData({ checked: true });\n element?.changeCheckAllHalfStatus(currentVal.length !== len - 1);\n // 取消全选\n element?.setCancel(enableValue.every((val) => currentVal.includes(val)));\n } else {\n element?.setData({ checked: false });\n }\n },\n // 设置可全选option选项\n handleOptionLinked() {\n const items = this.selectAllComponents('.t-checkbox-option');\n if (this.data.checkboxOptions.length) {\n items.forEach((item) => {\n item.setOptionLinked(true);\n });\n }\n },\n };\n}\n"]}