Files
Neo-ZQYY/apps/miniprogram - 副本/miniprogram/components/note-modal/note-modal.ts

80 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Component({
properties: {
/** 控制弹窗显示/隐藏 */
visible: {
type: Boolean,
value: false,
},
/** 客户名(弹窗标题显示) */
customerName: {
type: String,
value: '',
},
/** 初始评分 0-10 */
initialScore: {
type: Number,
value: 0,
},
/** 初始备注内容 */
initialContent: {
type: String,
value: '',
},
},
observers: {
'visible, initialScore, initialContent'(visible: boolean) {
if (visible) {
const clamped = Math.max(0, Math.min(10, this.data.initialScore))
this.setData({
starValue: clamped / 2,
content: this.data.initialContent,
score: clamped,
})
}
},
},
data: {
/** 星星值 0-5半星制 */
starValue: 0,
/** 内部评分 0-10 */
score: 0,
/** 备注内容 */
content: '',
},
methods: {
/** 星星评分变化 */
onRateChange(e: WechatMiniprogram.CustomEvent<{ value: number }>) {
const starVal = e.detail.value
this.setData({
starValue: starVal,
score: starVal * 2,
})
},
/** 文本内容变化 */
onContentChange(e: WechatMiniprogram.CustomEvent<{ value: string }>) {
this.setData({ content: e.detail.value })
},
/** 确认提交 */
onConfirm() {
if (!this.data.content.trim()) return
this.triggerEvent('confirm', {
score: this.data.score,
content: this.data.content.trim(),
})
},
/** 取消关闭 */
onCancel() {
this.triggerEvent('cancel')
},
/** 阻止冒泡 */
noop() {},
},
})