2023-04-17 16:14:18 +08:00

438 lines
13 KiB
JavaScript
Raw Permalink 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.

// pages/appeal/appeal.js
let miucms = require('../../utils/miucms.js')
let app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
loding: true,
voucherPictureList: [],
yourContactStata: 1, // 0 是啥都没选择 1 是微信号 2 微信二维码 3 电话号码
skipTime: 3,
complaintReason: "", //申诉理由
popupState: 0, // 申诉提交后的弹窗状态 0 是关闭状态 1 是弹窗未关注服务号的 2 弹窗已关注服务号的 3 是点击关注公众号的二维码
info: {},
newtoken: "",
issubscribe: 0, //issubscribe == 1 为已关注
contactWayInput: "",
qrcode: "",
QRCodeState: false, // 微信二维码的状态
uploadQRCodeSendData: { // 上传微信二维码的数据
aid: 0,
url: null,
src: ""
},
promptDialogState: false, // 提示框的状态
isPC: false, // 判断是否是PC端
focusState: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this
this.setData({
token: options.appealtoken
})
this.getinit()
// 获取用户设备信息
wx.getSystemInfo({
success: function (res) {
let platform = res.platform
if (platform == 'windows' || platform == 'mac') {
that.setData({
isPC: true
})
}
}
})
},
getinit() {
miucms.request(`${app.globalData.baseURL}/tenement/appeal`, {
token: this.data.token
}).then(res => {
// console.log(res);
if (res.code == 200) {
let data = res.data
this.setData({
matters: data.matters,
housingresource: data.housingresource,
info: data.info,
newtoken: data.token,
issubscribe: data.issubscribe,
qrcode: data.qrcode,
loding: false
})
} else {
wx.showModal({
title: '提示',
content: res.message,
showCancel: false,
success(res) {
if (res.confirm) {
this.abandon()
}
}
})
}
})
},
// 添加图片
addPicture(e) {
let kind = e.currentTarget.dataset.kind
wx.hideLoading()
wx.chooseImage({
count: kind == 'QRCode' ? 1 : (6 - this.data.voucherPictureList.length),
success: res => {
wx.showLoading({
title: '上传图片中...',
})
try { // 不知道下面的代码会不会报错,所以加个 try 隐藏Loading()
let tempFiles = res.tempFiles
let isLt10M = true;
tempFiles.forEach((item, index) => {
console.log("item", item, index);
if (index == tempFiles.length - 1 && kind == 'proof') {
wx.hideLoading()
}
let size = item.size / 1024 / 1024
if (size <= 10) {
kind == 'proof' ? this.upload_pi(item.path) : this.UploadQRCodeSend(item.path)
} else {
isLt10M = false;
}
if (!isLt10M) {
// 存在大于10M的只提示一次
wx.showModal({
title: '提示',
content: '图片大小不能超过10M',
})
}
})
} catch (error) {
wx.hideLoading()
}
},
fail: err => {
console.log(err);
wx.hideLoading()
}
})
},
// 上传图片凭证
upload_pi: function (imgUrl) {
var that = this;
const uploadTask = wx.uploadFile({
url: `${app.globalData.baseURL}/upload`,
filePath: imgUrl,
name: 'files',
formData: {
session: app.globalData.session,
},
header: app.globalData.header,
success: function (res) {
console.log("res", res);
try {
var data = JSON.parse(res.data);
if (data.aid > 0) {
// 长度<6个的时候再push
if (that.data.voucherPictureList.length < 6) {
that.data.voucherPictureList.push({
url: data.url,
aid: data.aid
})
that.setData({
voucherPictureList: that.data.voucherPictureList
})
} else {
wx.showToast({
title: '最多可上传6张',
icon: 'none'
})
}
} else {
wx.showToast({
title: data.state,
icon: 'none'
})
}
} catch (e) {
wx.showToast({
title: 'uploadCatch' + e,
icon: 'none'
})
}
},
fail: function (err) {
wx.showModal({
title: 'uploadFileErr',
content: err,
})
wx.hideLoading()
},
})
},
// 上传微信二维码
UploadQRCodeSend(imgUrl) {
let that = this
const uploadTask = wx.uploadFile({
url: `${app.globalData.baseURL}/tenement/publish/uploadweixinqrcode`,
filePath: imgUrl,
name: 'files',
header: app.globalData.header,
success: function (res) {
try {
res = JSON.parse(res.data);
console.log(res);
if (res.code == 200) {
that.setData({
['uploadQRCodeSendData.url']: res.data.url,
['uploadQRCodeSendData.aid']: res.data.aid,
['uploadQRCodeSendData.src']: imgUrl,
})
wx.showToast({
title: '上传成功',
})
} else {
wx.showModal({
title: '提示',
content: res.message
})
}
} catch (error) {
console.log(error);
wx.showToast({
title: error,
icon: 'none'
})
}
wx.hideLoading()
},
fail: err => {
wx.hideLoading()
}
})
},
// 删除已经上传的微信二维码
contactInformationwechatcut() {
this.setData({
['uploadQRCodeSendData.aid']: 0,
['uploadQRCodeSendData.url']: "",
['uploadQRCodeSendData.src']: "",
})
},
// 删除图片
deletePicture(e) {
let index = e.currentTarget.dataset.index
this.data.voucherPictureList.splice(index, 1)
this.setData({
voucherPictureList: this.data.voucherPictureList
})
},
// 选择联系方式
cutSelected(e) {
let index = e.currentTarget.dataset.index
if (this.data.yourContactStata > 0 || index == 2) {
this.setData({
contactWayInput: ""
})
}
if (this.data.yourContactStata == 2) {
this.setData({
uploadQRCodeSendData: {
aid: 0,
url: null
}
})
}
this.setData({
yourContactStata: index
})
},
abandon() {
wx.navigateBack({
delta: 1,
fail: () => {
// 稀奇古怪处理 因为navigateBack不能 返回第一个页面, 但是如果用户从 我的-发布 页面进来是第一个页面,所以 navigateBack 报错后直接 跳转 我的-发布, 如还有其他入口需要重新看一下
wx.navigateTo({
url: '/pages/user/user?tab=publish',
})
}
})
},
submit() {
let yourContactStata = this.data.yourContactStata
if (yourContactStata == 0) {
wx.showToast({
icon: 'error',
title: '请选择联系方式',
})
return
}
if (this.data.complaintReason.length == 0) {
wx.showToast({
icon: 'error',
title: '请填写申诉理由',
})
return
}
let data = {
...this.data.info
}
if (yourContactStata == 1) {
if (this.data.contactWayInput.indexOf('wxid_') == 0) {
this.bindPromptDialog()
return
}
data['wechat'] = this.data.contactWayInput
} else if (yourContactStata == 2) {
data['wechatdata'] && (data['wechatdata']['aid'] = this.data.uploadQRCodeSendData.aid)
data['wechatdata'] && (data['wechatdata']['url'] = this.data.uploadQRCodeSendData.url)
} else if (yourContactStata == 3) {
data['mobile'] = this.data.contactWayInput
}
data['image'] = this.data.voucherPictureList
data['reason'] = this.data.complaintReason
miucms.request(`${app.globalData.baseURL}/tenement/appeal/submit`, {
info: data,
token: this.data.newtoken
}).then(res => {
if (res.code == 200) {
if (this.data.issubscribe == 0) {
this.setData({
popupState: 1
})
} else {
this.setData({
popupState: 2
})
this.countdownJump()
}
} else {
wx.showModal({
title: '提示',
content: res.message
})
}
})
},
// 倒计时跳转
countdownJump() {
let timer = setInterval(() => {
this.setData({
skipTime: this.data.skipTime - 1
})
if (this.data.skipTime <= 0) {
clearInterval(timer)
wx.redirectTo({
url: '/pages/user/user?tab=publish',
})
}
}, 1000)
},
close() {
wx.redirectTo({
url: '/pages/user/user?tab=publish',
})
},
// 点击打开二维码
openQRCode() {
this.setData({
QRCodeState: !this.data.QRCodeState
})
},
bindPromptDialog() {
this.setData({
promptDialogState: !this.data.promptDialogState
})
},
bindfocusfocus() {
if (!this.data.isPC) {
this.setData({
focusState: true
})
}
},
bindblurblur() {
this.setData({
focusState: false
})
},
// 输入框的输入
popUpInput(e) {
let value = e.detail.value
value = value.substr(0, 200)
this.setData({
complaintReason: value
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
})