123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- Page({
- data: {
- address: '安平镇安坪村安平小区12栋305室',
- contact: '',
- phone: '',
- repairType: '',
- description: '',
- imageList: [],
- showNotification: true,
- countDown: 3
- },
- onLoad: function(options) {
- this.startCountDown();
- },
- startCountDown: function() {
- let that = this;
- let timer = setInterval(function() {
- if (that.data.countDown > 0) {
- that.setData({
- countDown: that.data.countDown - 1
- });
- } else {
- clearInterval(timer);
- }
- }, 1000);
- },
- closeNotification: function() {
- if (this.data.countDown <= 0) {
- this.setData({
- showNotification: false
- });
- }
- },
- goBack: function() {
- wx.navigateBack();
- },
- inputContact: function(e) {
- this.setData({
- contact: e.detail.value
- });
- },
- inputPhone: function(e) {
- const value = e.detail.value;
- const phoneNumber = value.replace(/\D/g, '');
- this.setData({
- phone: phoneNumber
- });
- },
- validatePhone: function(phone) {
- const phoneReg = /^1[3-9]\d{9}$/;
- return phoneReg.test(phone);
- },
- showRepairTypeSelector: function() {
- let that = this;
- wx.showActionSheet({
- itemList: ['水管漏水', '水表故障', '水龙头故障', '其他问题'],
- success: function(res) {
- const types = ['水管漏水', '水表故障', '水龙头故障', '其他问题'];
- that.setData({
- repairType: types[res.tapIndex]
- });
- }
- });
- },
- inputDescription: function(e) {
- this.setData({
- description: e.detail.value
- });
- },
- chooseImage: function() {
- let that = this;
- if (that.data.imageList.length >= 10) {
- wx.showToast({
- title: '最多只能上传10张图片',
- icon: 'none'
- });
- return;
- }
-
- wx.chooseMedia({
- count: 3 - that.data.imageList.length,
- mediaType: ['image'],
- sourceType: ['album', 'camera'],
- sizeType: ['compressed'],
- success: function(res) {
- let tempFiles = res.tempFiles;
- let validFiles = [];
-
- for (let i = 0; i < tempFiles.length; i++) {
- const file = tempFiles[i];
- if (file.size <= 5 * 1024 * 1024) {
- validFiles.push(file.tempFilePath);
- } else {
- wx.showToast({
- title: '图片大小不能超过5M',
- icon: 'none'
- });
- }
- }
-
- if (validFiles.length > 0) {
- let newImageList = that.data.imageList.concat(validFiles);
- that.setData({
- imageList: newImageList
- });
- }
- }
- });
- },
- previewImage: function(e) {
- let index = e.currentTarget.dataset.index;
- wx.previewImage({
- current: this.data.imageList[index],
- urls: this.data.imageList
- });
- },
- deleteImage: function(e) {
- let index = e.currentTarget.dataset.index;
- let imageList = this.data.imageList;
- imageList.splice(index, 1);
- this.setData({
- imageList: imageList
- });
- },
- submitRepair: function() {
- if (!this.data.contact) {
- wx.showToast({
- title: '请输入联系人',
- icon: 'none'
- });
- return;
- }
-
- if (!this.data.phone) {
- wx.showToast({
- title: '请输入联系电话',
- icon: 'none'
- });
- return;
- }
-
- if (!this.validatePhone(this.data.phone)) {
- wx.showToast({
- title: '请输入正确的手机号',
- icon: 'none'
- });
- return;
- }
-
- if (!this.data.repairType) {
- wx.showToast({
- title: '请选择报修类型',
- icon: 'none'
- });
- return;
- }
-
- if (!this.data.description) {
- wx.showToast({
- title: '请输入故障说明',
- icon: 'none'
- });
- return;
- }
-
- const submitData = {
- address: this.data.address,
- contact: this.data.contact,
- phone: this.data.phone,
- repairType: this.data.repairType,
- description: this.data.description,
- images: this.data.imageList
- };
-
- console.log('提交的数据:', submitData);
-
- wx.showLoading({
- title: '提交中...',
- });
-
- setTimeout(() => {
- wx.hideLoading();
- wx.showToast({
- title: '报修提交成功',
- icon: 'success',
- duration: 2000,
- success: function() {
- setTimeout(() => {
- wx.navigateBack();
- }, 2000);
- }
- });
- }, 1500);
- }
- });
|