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,0CAAE,MAAM,CAAC;YACpC,CAAC;SACF,CAAC;IAeJ,CAAC;IAbC;;;OAGG;IACH,mBAAmB,CAAC,WAAmB;QACrC,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC;IAC9E,CAAC;IAED,OAAO;QACL,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;CACF,CAAA;AApHoB,YAAY;IADhC,WAAW,EAAE;GACO,YAAY,CAoHhC;eApHoB,YAAY","file":"picker-column.js","sourcesContent":["import { SuperComponent, wxComponent } from '../common/src/index';\nimport config from '../common/config';\nimport props from './picker-item-props';\n\nconst itemHeight = 80;\nconst DefaultDuration = 600;\n\nconst { windowWidth } = wx.getSystemInfoSync();\n\nconst rpx2px = (rpx) => Math.floor((windowWidth * rpx) / 750);\n\nconst range = function (num: number, min: number, max: number) {\n return Math.min(Math.max(num, min), max);\n};\n\n@wxComponent()\nexport default class PickerColumn extends SuperComponent {\n relations = {\n './picker': {\n type: 'parent' as 'parent',\n },\n };\n\n properties = props;\n\n observers = {\n value(this: PickerColumn) {\n this.updateColumns();\n },\n options(this: PickerColumn) {\n this.updateColumns();\n },\n };\n\n data = {\n prefix: `${config.prefix}-picker-column`,\n offset: 0, // 滚动偏移量\n duration: 0, // 滚动动画延迟\n };\n\n methods = {\n onTouchStart(event) {\n this.StartY = event.touches[0].clientY;\n this.StartOffset = this.data.offset;\n this.setData({ duration: 0 });\n },\n\n onTouchMove(event) {\n const { StartY, StartOffset, itemHeight } = this;\n\n // touch偏移增量\n const touchDeltaY = event.touches[0].clientY - StartY;\n const deltaY = this.calculateViewDeltaY(touchDeltaY);\n\n this.setData({\n offset: range(StartOffset + deltaY, -(this.getCount() * itemHeight), 0),\n duration: DefaultDuration,\n });\n },\n\n onTouchEnd() {\n const { offset } = this.data;\n const { options } = this.properties;\n\n if (offset === this.StartOffset) {\n return;\n }\n // 调整偏移量\n const index = range(Math.round(-offset / this.itemHeight), 0, this.getCount() - 1);\n this.setData({\n offset: -index * this.itemHeight,\n });\n\n if (index === this._selectedIndex) {\n return;\n }\n\n wx.nextTick(() => {\n const changeObj = {\n index,\n value: options[index],\n };\n\n this._selectedIndex = index;\n this._selectedValue = options[index];\n this.triggerEvent('change', changeObj);\n\n const picker = this.getRelationNodes('./picker')?.[0];\n if (picker) {\n picker.triggerChange({\n ...changeObj,\n column: this.columnIndex || 0,\n });\n }\n });\n },\n\n // 刷新选中状态\n updateColumns() {\n const { options, value } = this.properties;\n\n const index = options.findIndex((item) => item.value === value);\n const selectedIndex = index > 0 ? index : 0;\n\n this.setData({ offset: -selectedIndex * this.itemHeight });\n\n this._selectedIndex = selectedIndex;\n this._selectedValue = options[selectedIndex];\n },\n\n resetOrigin() {\n this.updateColumns();\n },\n\n getCount() {\n return this.data?.options?.length;\n },\n };\n\n /**\n * 将屏幕滑动距离换算为视图偏移量 模拟渐进式滚动\n * @param touchDeltaY 屏幕滑动距离\n */\n calculateViewDeltaY(touchDeltaY: number): number {\n return Math.abs(touchDeltaY) > itemHeight ? 1.2 * touchDeltaY : touchDeltaY;\n }\n\n created() {\n this.StartY = 0;\n this.StartOffset = 0;\n this.itemHeight = rpx2px(itemHeight);\n }\n}\n"]}