import themeChangeBehavior from 'tdesign-miniprogram/mixins/theme-change'; import { list, skylineList } from './data/index'; Page({ behaviors: [themeChangeBehavior], data: { list: [], currentYear: new Date().getFullYear(), isSkyline: false, formData: { customerName: '', projectSource: '', projectLeader: '', clientdemand: '', handovertasks: '', remarks: '' }, }, onLoad(options) { const { path, q, skyline } = options; // console.log(path); let compList = []; this.skyline = skyline; if (this.skyline) { compList = skylineList; } else { compList = list; } this.setData({ list: compList, isSkyline: !!skyline, }); if (q) { const str = this.getQueryByUrl(decodeURIComponent(q)); console.log(str, str.page); wx.navigateTo({ url: `/pages/${str.page}/${str.page}`, }); } this.trdPrivacy = this.selectComponent('#trdPrivacy'); }, showPrivacyWin() { this.trdPrivacy.showPrivacyWin(); }, clickHandle(e) { console.log("Hello World!") let { name, path = '' } = e.detail.item; if (!path) { name = name.replace(/^[A-Z]/, (match) => `${match}`.toLocaleLowerCase()); name = name.replace(/[A-Z]/g, (match) => { return `-${match.toLowerCase()}`; }); path = `/pages/${name}/${this.skyline ? 'skyline/' : ''}${name}`; } wx.navigateTo({ url: path, fail: () => { wx.navigateTo({ url: '/pages/home/navigateFail/navigateFail', }); }, }); }, onShareAppMessage() { return { title: 'TDesign UI', path: '/pages/home/home', }; }, getQueryByUrl(url) { const data = {}; const queryArr = `${url}`.match(/([^=&#?]+)=[^&#]+/g) || []; if (queryArr.length) { queryArr.forEach((para) => { const d = para.split('='); const val = decodeURIComponent(d[1]); if (data[d[0]] !== undefined) { data[d[0]] += `,${val}`; } else { data[d[0]] = val; } }); } return data; }, goSkyline() { wx.navigateTo({ url: '/pages/home/home?skyline=1', }); }, onSubmit(e){ // 数据验证, const {customerName, customerContact, projectSource, projectLeader } = this.data.formData; if (!customerName) return wx.showToast({ title: '请输入客户名称', icon: 'none' }); if (!projectSource) return wx.showToast({ title: '请输入项目来源', icon: 'none' }); if (!projectLeader) return wx.showToast({ title: '请输入负责人', icon: 'none' }); wx.request({ url: 'https://bayizhinengjf.vip.cpolar.cn/contact', method: 'POST', data: this.data.formData, success: (res) => { // 请求成功处理 wx.showToast({ title: '提交成功', icon: 'success' }) }, fail: (err) => { // 请求失败处理 wx.showToast({ title: '提交失败', icon: 'none' }) console.log('提交失败:', err) }, complete: () => { // 无论成功失败都取消加载状态 this.setData({ loading: false }) } }) }, onFormChange(e) { const { field, value } = e.detail; this.setData({ [`formData.${field}`]: value }); }, });