Files

154 lines
4.2 KiB
JavaScript
Raw Permalink Normal View History

2025-08-15 14:05:08 +08:00
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) {
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}`;
}
2025-08-17 22:15:20 +08:00
wx.showModal({
title: '提示',
content: '确定信息核实准确无误?',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
}
}),
2025-08-15 14:05:08 +08:00
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: '提交成功',
2025-08-17 22:15:20 +08:00
icon: 'success',
duration: 1000 // 持续1.5秒
2025-08-15 14:05:08 +08:00
})
2025-08-17 22:15:20 +08:00
setTimeout(() => {
wx.navigateTo({
url: '/pages/success/success'
})
}, 500)
2025-08-15 14:05:08 +08:00
},
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
});
},
});