statisticsItem.js 2.36 KB
// components/dateScreen/dateScreen.js
Component({
	options: {
		multipleSlots: true,
	},
	/**
	 * 组件的属性列表
	 */
	properties: {
		// hideColon 是否隐藏colon , 默认false
		// name : - 唯一key  , 数据的键值
		// label : 文案
		// col : 占24分之几
		// valueWidth : 值的宽度,默认为100%
		// labelWidth : 标签宽度,默认为150px
		// slot : 整体的插槽名,优先级高于name
		// itemStyle: 每一项的样式
		// tooltip: boolean  是否用tooltip 展示data数据
		// tooltipProps: el-tooltip 的传参
		// render ?:(h,{ data,schemaItem,schema } )=>{}   自定义渲染
		// isHide 是否隐藏  (data)=>boolean ||  boolean
		// parentProps:{
		//	 className:'text-hide'  // 默认
		// },
		schema: {
			type: Array,
			value: [],
			observer: function (schema) {
				const hasMore = Array.isArray(schema) && schema.some((item) => item && item.isMore);
				this.setData({
					hasMore,
					expanded: hasMore ? this.data.expanded : false,
				});
				this.measureMoreHeight();
			},
		},
		data: {
			type: Object,
			value: {},
		},
		title: {
			type: String,
			value: "",
		},
		beTap: {
			type: Boolean,
			value: true,
		},
		hideValue: {
			type: String,
			value: "2",
		},
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		expanded: false,
		hasMore: false,
		moreHeight: 0,
		tooltipIconPath: "/images/tips-icon.png",
	},

	lifetimes: {
		ready() {
			this.measureMoreHeight();
		},
	},
	/**
	 * 组件的方法列表
	 */
	methods: {
		onToggleMore() {
			if (!this.data.hasMore) return;

			if (this.data.expanded) {
				this.setData({ expanded: false });
				return;
			}

			this.measureMoreHeight(() => {
				this.setData({ expanded: true });
			});
		},

		handleTapItem() {
			this.triggerEvent("tapItem", {
				// item: this.data.normalizedList[nextIndex],
			});
		},
		measureMoreHeight(done) {
			wx.nextTick(() => {
				const query = this.createSelectorQuery().in(this);
				query.select("#moreMeasureInner").boundingClientRect();
				query.exec((res) => {
					const rect = res && res[0];
					const height = Math.max(0, Math.round((rect && rect.height) || 0));
					console.log(height);
					if (height !== this.data.moreHeight) {
						this.setData({ moreHeight: height }, () => {
							if (typeof done === "function") done();
						});
						return;
					}
					if (typeof done === "function") done();
				});
			});
		},
	},
});