// pages/bookServices/detail/components/note/note.js const app = getApp(); import moment from 'moment' Component({ /** * 组件的属性列表 */ properties: { bookInfo: { type: Object, value: {}, }, }, /** * 组件的初始数据 */ data: { inputStyle: "padding:10rpx", placeholderstyle: "font-size:28rpx", flag: false, // 输入框是否显示 submitType: "new", // 新建 or 编辑 showNoteDialog: false, showInput: false, userName: "", mannder: "", content: "", lock: true, phoneError: false, pageCount: { page: 1, total: 0, }, isMore: null, onlineQuestionsList: [], activeValues: 0, loading: false, noList: false, }, onLoad() {}, /** * 组件的方法列表 */ methods: { onReachBottom() { const flag = this.data.noteList.length < this.data.pageCount.total; if (flag) { this.setData({ isMore: true, "pageCount.page": this.data.pageCount.page + 1, }); this.getDataList(); } else { this.setData({ isMore: true, }); setTimeout(() => { this.setData({ isMore: false, }); }, 100); } }, handleSubmitTitle() { this.setData({ submitTitle: this.properties.bookInfo.name, }); }, openDialog() { this.setData({ submitTitle: this.properties.bookInfo.name, showNoteDialog: true, }); }, closeDialog() { this.setData({ flag: false, showNoteDialog: false, userName: "", mannder: "", content: "", }); }, bindTnputBlur: function (e) { this.setData({ userName: e.detail.value, }); }, onPhoneInput(e) { const { phoneError } = this.data; if (e.detail.value) { const isPhoneNumber = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(e.detail.value); if (phoneError === isPhoneNumber) { this.setData({ phoneError: !isPhoneNumber, mannder: e.detail.value, }); } } else { this.setData({ phoneError: false, mannder: '' }); } }, bindTextAreaBlur: function (e) { this.setData({ content: e.detail.value, }); }, // 弹窗确定按钮 confirmSuggest() { if (this.data.lock) { this.data.lock = false; if (this.data.userName.replace(/^\s*|\s*$/g, "") == '') { this.data.lock = true; wx.showToast({ title: "联系人不能为空", icon: 'none', duration: 1000 }) return } if (this.data.mannder.replace(/^\s*|\s*$/g, "") == '') { this.data.lock = true; wx.showToast({ title: "联系方式不能为空", icon: 'none', duration: 1000 }) return } if (this.data.content.replace(/^\s*|\s*$/g, "") == '') { this.data.lock = true; wx.showToast({ title: "反馈内容不能为空", icon: 'none', duration: 1000 }) return } if (this.data.phoneError) { this.data.lock = true; return } let submitData = { content: this.data.content.replace(/^\s*|\s*$/g, ""), name: this.data.userName.replace(/^\s*|\s*$/g, ""), email: "", phone: this.data.mannder.replace(/^\s*|\s*$/g, "") }; var data = { topicIdOrRefCode: "onlineQuestioning", name: this.properties.bookInfo.name, content: JSON.stringify(submitData), type: "ProductComment", cmsTypeRefCode: "", newDataListRequest: [] }; app.MG.ugc.newTopicMessage(data).then(res => { this.data.lock = true; if (res) { wx.showToast({ title: "提交成功", icon: 'success', duration: 1000, }) this.closeDialog(); this.getDataList(); } }); } }, handleChange(e) { this.setData({ activeValues: e.detail.value, }); }, // 格式化笔记时间 convertTimestamp(timestamp) { const isoDate = new Date(timestamp); const year = isoDate.getFullYear(); const month = String(isoDate.getMonth() + 1).padStart(2, "0"); const day = String(isoDate.getDate()).padStart(2, "0"); const hours = String(isoDate.getHours()).padStart(2, "0"); const minutes = String(isoDate.getMinutes()).padStart(2, "0"); const seconds = String(isoDate.getSeconds()).padStart(2, "0"); const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; return formattedDate; }, changeLoading() { this.setData({ loading: true, }); }, changeNoList() { this.setData({ noList: true, }); }, // 获取提问列表 getDataList() { let that = this if (!this.data.isMore) { this.setData({ loading: true, }); } this.setData({ noList: false, }); let topicId; app.MG.ugc .getTopicMessageList({ appRefCode: app.config.appRefCode, topicIdOrRefCode: 'onlineQuestioning', start: that.data.pageCount.page * 5 - 5, size: 5, sort: { type: 'Desc', field: 'CreateDate' }, }).then((res) => { if (!res.datas.length) { return this.setData({ loading: false, noList: true, noteList: res.datas, }); } // notePage.value.total = res.totalSize res.datas.forEach((item) => { item.title = JSON.parse(item.content).content; item.createDate = moment(item.createDate).format("YYYY-MM-DD HH:mm:ss"); item.updateDate = moment(item.updateDate).format("YYYY-MM-DD HH:mm:ss"); item.feedBack = item.feedBack ? item.feedBack : '暂未回复' }); this.setData({ "pageCount.total": res.totalSize, onlineQuestionsList: res.datas, loading: false, noList: false, }); console.log(this.data.onlineQuestionsList, 3456) }); }, }, });