2025-02-24 18:58:52 +08:00

2391 lines
81 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/edit/edit.js
const chooseLocation = requirePlugin('chooseLocation');
var app = getApp()
var config = {};
var id = 0;
var timer = null;
var miucms = require('../../utils/miucms.js');
var WxParse = require('../../wxParse/wxParse.js');
var tempFilePaths = [],
tempFilePathVideo = [];
var tempFilePath = '';
var submit = false;
let mapKey = 'IGSBZ-4B7KX-MOG4O-TN3JQ-KA6M5-32FGO'
let time = new Date()
let todayDate = '',
lastYearDate = '';
Page({
/**
* 页面的初始数据
*/
data: {
uploadData: "", // 上传图片需要的 数据
loding: true,
intermediaryObj: {
1: "中介",
2: "非中介",
3: "房东",
4: "有房招室友",
5: "其他",
6: "求房源",
},
// address:'',
isrefusedAuthLocation: 0, //是否拒绝授权地址
edit: false,
city: {},
latitude: '',
longitude: '',
info: {
intermediary: {
name: '发布者身份',
value: '',
data: [],
title: "intermediary",
need: true
},
'type': {
name: '出租方式',
title: 'type',
data: {},
value: '',
need: true
},
location: {
data: {},
value: '',
title: "location",
name: '所在区域',
need: true
},
gender: {
name: '租客性别要求',
title: 'gender',
data: [],
value: '',
need: true
},
property: {
title: 'property',
value: 'null',
name: '房屋类型',
data: [],
list: {},
need: true
},
rentalduration: {
title: 'rentalduration',
value: '',
name: '出租时长',
placeholder: '请填写数字0为租期不限',
unit: '月',
need: true,
numberType: true
},
rent: {
title: 'rent',
value: '',
name: '',
placeholder: '请填写数字',
unit: '',
need: true,
numberType: true
},
floor: {
title: 'floor',
value: '',
name: '所在楼层',
placeholder: '请填写数字',
unit: '楼',
need: true,
numberType: true
},
acreage: {
title: 'acreage',
value: '',
name: '面积',
placeholder: '请填写数字',
unit: '',
numberType: true
},
subject: {
title: 'subject',
value: '',
name: '标题',
placeholder: '请填写标题',
need: true
},
village: {
title: 'village',
value: '',
name: '所在小区',
placeholder: '请填写小区名称'
},
school: {
title: 'school',
value: '',
name: '附近学校',
placeholder: '可输入附近的学校最多可输入3个'
},
distanceschool: {
title: 'distanceschool',
value: '',
name: '距离学校',
placeholder: '可输入与学校的距离'
},
wechat: {
title: 'wechat',
value: '',
name: '个人微信号',
placeholder: '请正确填写',
unit: '',
},
whatsapp: {
title: 'whatsapp',
value: '',
name: 'WhatsApp',
placeholder: '请正确填写',
unit: '',
},
tel: {
title: 'tel',
value: '',
name: '电话号码',
placeholder: '请正确填写',
unit: '',
numberType: true
},
address: {
title: 'address',
value: '',
name: '地址',
placeholder: '可填写地段、路名、社区、地址等'
},
introduction: {
title: 'introduction',
value: '',
name: '个人情况介绍',
placeholder: '介绍一下房东/合租人/室友的情况。可以写下作息习惯、性格、是否有养宠物等'
},
message: {
title: 'message',
value: '',
name: '其他描述',
placeholder: '可以填写如需签约至多久,和谁签约,如何交房租,房子是否断隔房、房租以外的费用项支付规则、户型家具、生活配套、地理位置(距离学校多远)等'
},
leasetime: {
value: 0,
name: '起租日期'
}
},
imgs: [],
types: '',
token: '',
uniqid: '',
step: 1,
url: '',
status: 0,
user: {},
q: '',
write_long_textarea: false,
questions: [],
videos: [],
options: {},
leasetime: '', //起租日期
startDate: '',
isInput: false, //当前是否为输入附近学校或小区的状态
timestamp: "", // 发布时间
updatetime: "", // 更新时间
aroundSchoolList: [],
unfoldState: false, // 发布须知的状态
triggerRules: 0, // 触发规则状态 0 是未触发 1 是触发规则 1 2 是触发规则2
current: 2019,
leaseTimeValue: [11],
floorValue: [12],
nearSchoolList: [], // 附近学校的数据
contactInformationData: [{
title: '微信',
value: ''
}], // 联系方式的数据
contactInformationState: 0, // 联系方式中微信的状态 0 是 初始状态 1 是 填写微信号 2 是上传二维码
ofDate: [], // 起租日期数据
dayList: {},
finalizedDate: [],
week: ['日', '一', '二', '三', '四', '五', '六'],
calculateOfDateList: [], // 起租日期的日历
calculateOfDateTime: {},
fieldinfo: [],
inputList: ['acreage'],
contactInformation: 'contactInformation',
popUpIs: '', // 弹窗的 is
popUpdate: [], // 目标数据
popUpSubtitle: '',
popUpStepState: '', // 0是啥都没有 1 是 保存 2 是保存加下一步
fieldinfoNew: [],
step: 0, // 步数
newcity: {},
aa: [{
name: '出租方式',
popUpIs: 'AListOF',
popUpStepState: 0,
it: 'basic',
field: "type"
}, {
name: '找人合租',
popUpIs: 'AListOF',
popUpStepState: 1,
it: 'basic',
}, {
name: '整套出租',
popUpIs: 'twoLines',
popUpStepState: 1,
it: 'basic'
}, {
name: '出租时长',
popUpIs: 'AListOF',
popUpStepState: 1,
it: 'basic',
field: "rentalduration"
}, {
name: '选择租期',
popUpIs: 'leaseTime',
popUpStepState: 2,
it: 'basic'
}, {
name: '起租日期',
popUpIs: 'AListOF',
popUpStepState: 1,
it: 'basic',
field: "leasetime"
}, {
name: '选择日期',
popUpIs: 'ofDate',
popUpStepState: 1,
it: 'basic'
}, {
name: '年租',
popUpIs: 'unilineInput',
popUpStepState: 2,
it: 'basic',
field: "rent"
}, {
name: '月租',
popUpIs: 'unilineInput',
popUpStepState: 2,
it: 'basic',
field: "rent"
}, {
name: '周租',
popUpIs: 'unilineInput',
popUpStepState: 2,
it: 'basic',
field: "rent"
}, {
name: '房屋类型',
popUpIs: 'twoLines',
popUpStepState: 1,
it: 'basic',
field: "property"
}, {
name: '所在楼层',
popUpIs: 'floor',
popUpStepState: 2,
it: 'basic',
field: "floor"
}, {
name: '面积',
popUpIs: 'unilineInput',
popUpStepState: 2,
it: 'basic',
field: "acreage"
}, {
name: '所在区域',
popUpIs: 'area',
popUpStepState: 1,
field: "location"
}, {
name: '地址',
popUpIs: 'multilineInput',
popUpStepState: 2,
field: "address"
}, {
name: '附近学校',
popUpIs: 'nearSchool',
popUpStepState: 2,
field: "school"
}, {
name: '租客性别要求',
popUpIs: 'AListOF',
popUpStepState: 1,
field: "gender"
}, {
name: '发布者身份',
popUpIs: 'AListOF',
popUpStepState: 0,
field: "intermediary"
}, {
name: '房屋视频',
popUpIs: 'pop-up-HomeVideo',
popUpStepState: 2,
field: "video"
}, {
name: '房屋照片',
popUpIs: 'pop-up-homePhoto',
popUpStepState: 2,
field: "images"
}, {
name: '更多介绍',
popUpIs: 'multilineInput',
popUpStepState: 2,
field: "introduction"
}, {
name: '其他描述',
popUpIs: 'multilineInput1',
popUpStepState: 2,
field: "message"
}, {
name: '微信',
popUpIs: 'contactInformation',
popUpStepState: 2,
field: "wechat"
}, {
name: '标题',
popUpIs: 'multilineInput',
popUpStepState: 3,
field: "subject"
}, {
name: '电梯',
popUpIs: 'AListOF',
popUpStepState: 1,
field: "elevator"
}, {
name: '晾晒区',
popUpIs: 'AListOF',
popUpStepState: 1,
field: "sunshinearea"
}],
popUpit: "",
popUpOrder: ['status', 'basic', 'address', 'identity', 'upload', 'introduce', 'contact', 'info'],
newinfo: {},
areaRegionIndex: 0,
newToken: "", // 新的token
QRCodeUrl: '', // 上传二维码的解析url
publishingrules: [],
focustitle: "",
// 选中起租提前的年月日
pitchyear: null,
pitchmonth: null,
pitchday: null,
isPC: false, // 判断是否是PC端
focusState: false,
isAuthorization: 0,
intermediaryVlaue: 0, // 作者的身份
aboutRulesList: {}, // 关于发布的数据
getWechatQRCodeState: false,
verified: 0, // 是否是认证房源
countDown: 2, // 倒计时
placeAroundData: [], // 所属小区
residentialPopSelectState: false,
residentialPopFillState: false,
housingEstate: {
field: "communityname",
popupwindow: 1,
required: 0,
title: "所属小区",
type: "communityname",
},
longitudeLatitude: {
1: {
n: 22.2795,
e: 114.1692
},
2: {
n: 22.3171,
e: 114.1794
},
3: {
n: 22.3926,
e: 114.1332
}
},
isNewVersions: true,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let intermediaryObj = this.data.intermediaryObj
wx.showLoading({
title: intermediaryObj[options['intermediary'] || 3],
})
this.calculateOfDate()
wx.showLoading({
title: '加载中',
})
let nowDate = new Date()
let that = this;
this.setData({
verified: options.verified || 0,
uniqid: options.uniqid || '',
token: options.token || '',
types: options.types || 'plus',
info: this.data.info,
intermediaryVlaue: options.intermediary || 3,
startDate: [nowDate.getFullYear(), nowDate.getMonth() + 1, nowDate.getDate()].join('-')
})
if (options.types == 'edit') {
wx.setNavigationBarTitle({
title: '编辑信息',
})
} else {
wx.setNavigationBarTitle({
title: '发布',
})
}
this.get_config()
wx.getSystemInfo({
success: function (res) {
let platform = res.platform
if (platform == 'windows' || platform == 'mac') {
that.setData({
isPC: true
})
}
}
})
},
choosel() {
let newinfo = this.data.newinfo
let latitude = newinfo['latitude']
let longitude = newinfo['longitude']
if (newinfo.location && !latitude) {
this.data.fieldinfoNew["location"].choices.forEach(el => {
el.choices.forEach(e => {
if (newinfo.location && newinfo.location.indexOf(e.value) >= 0) {
let longitudeLatitude = this.data.longitudeLatitude
latitude = longitudeLatitude[(e.key >>> 0) || 1]['n']
longitude = longitudeLatitude[(e.key >>> 0) || 1]['e']
}
})
})
}
if (!latitude) latitude = 22.297759
if (!longitude) longitude = 114.179495
const key = 'MVNBZ-PEFWI-O4OGT-5ADVJ-7QAYJ-NBFY4'; //使用在腾讯位置服务申请的key
const referer = 'hao'; //调用插件的app的名称
const location = JSON.stringify({
latitude,
longitude,
});
wx.navigateTo({
url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}`
});
},
// 如果用户已经同意授权。则开始获取数据
islogin() {
wx.showLoading({
title: '加载中',
})
this.get_config()
},
get_config() {
var that = this;
if (app.globalData.config.lists) {
config = app.globalData.config;
that.setData({
info: that.data.info,
status: app.globalData.status,
user: app.globalData.user,
userIntermediary: app.globalData.user['intermediary'] || 0
})
app.globalData.notice = false;
this.newPublish()
} else {
setTimeout(function () {
that.get_config()
}, 200)
}
},
// 获取关于发布
getAbout() {
if (app.globalData['aboutRulesList']) {
this.setData({
aboutRulesList: app.globalData['aboutRulesList'],
popUpIs: "about"
})
return
}
miucms.request(`${app.globalData.baseURL}/tenement/v2.Publish/about`).then(res => {
app.globalData['aboutRulesList'] = res.data
this.setData({
aboutRulesList: res.data,
popUpIs: "about"
})
})
},
// 新的获取发布数据
typetouList: [],
newPublish() {
wx.showLoading({
title: '加载中',
})
let requestData = {}
let intermediary = this.data.intermediaryVlaue
if (this.data.types == 'edit' || this.data.types == 'edit1') {
requestData = {
uniqid: this.data.uniqid,
token: this.options.token,
intermediary,
}
} else {
requestData = {
uniqid: this.data.uniqid,
intermediary,
}
}
miucms.request(`${app.globalData.baseURL}/tenement/v2/api/publish`, requestData).then(res => {
wx.hideLoading()
this.setData({
loding: false
})
if (res.code == 401) {
this.setData({
isAuthorization: 1,
})
}
if (res.code != 200) {
wx.showModal({
title: '提示',
content: res.message
})
return
}
let data = res.data
let fieldinfoNew = []
let locationhead = ""
let locationtail = ""
for (const key in data.fieldinfo) {
let choices = null
data.fieldinfo[key].forEach(element => {
if (!element) return
if (element.field == 'type') {
let choices = element.choices
let choicesnew = []
let newfield = element.field
choices.forEach(el => {
if (!el) return
if ((this.data.types == 'edit' || this.data.types == 'edit1') && el.key == data.info.type) {
choices.forEach(e => {
if (e.key == [Math.trunc(el.key)]) data.info.type = e.value + '>>' + el.value
})
}
if (el.key % 1 == 0) {
choicesnew[el.key - 1] = {
value: el.value,
key: el.key,
field: newfield,
choices: []
}
this.typetouList.push(el.value)
} else {
choicesnew[Math.trunc(el.key) - 1]['choices'].push({
value: el.value,
key: el.key,
field: newfield
})
}
});
fieldinfoNew[element.field] = ({
choices: choicesnew,
field: element.field,
title: element.title,
type: element.type,
popupwindow: element.popupwindow,
required: element.required,
})
return
}
if (element.field == 'rentalduration') {
if (this.data.types == 'edit' || this.data.types == 'edit1') {
element.choices.forEach((el, i) => {
if (el.key == data.info.rentalduration) {
this.data.leaseTimeValue = [i]
data.info.rentalduration = el.value
}
})
}
fieldinfoNew[element.field] = ({
choices: [{
field: element.field,
value: "不限租期",
}, {
field: element.field,
value: "选择租期",
choices: element.choices,
}],
field: element.field,
title: element.title,
type: element.type,
popupwindow: element.popupwindow,
required: element.required,
})
return
}
if (element.field == "intermediary" && data.type == 'edit') {
element.choices.forEach(el => {
if (el.key == 6) el['disabled'] = 1
})
}
if (element.field == 'leasetime') {
fieldinfoNew[element.field] = ({
choices: [{
field: "leasetime",
value: "随时",
}, {
field: "leasetime",
value: "选择日期",
choices: element.choices,
}],
field: element.field,
title: element.title,
type: element.type,
popupwindow: element.popupwindow,
required: element.required,
})
return
}
if (element.field == 'property' || element.field == 'gender' || element.field == 'intermediary' || element.field == 'elevator' || element.field == 'sunshinearea') {
choices = []
if (element.choices.length >= 0) {
if (this.data.types == 'edit' || this.data.types == 'edit1') {
element.choices.forEach(el => {
if (el.key == data.info[element.field]) {
data.info[element.field] = el.value
}
})
}
element.choices.forEach(ele => {
ele['field'] = element.field
});
} else {
let elementnew = element.choices
element.choices = []
for (const key in elementnew) {
element.choices.push({
'field': element.field,
'value': elementnew[key],
'key': key
})
}
}
fieldinfoNew[element.field] = ({
choices: element.choices,
field: element.field,
title: element.title,
type: element.type,
popupwindow: element.popupwindow,
required: element.required,
})
return
}
if (element.field == 'location') {
let field = element.field
let choices = element.choices
let choicesnew = []
choices.forEach((el, i) => {
if (!el) return
if (this.data.types == 'edit' || this.data.types == 'edit1') {
if (el.key == data.info[field]) {
locationtail = el.value
}
if (el.key == [Math.trunc(data.info[field])]) {
locationhead = el.value
this.data.areaRegionIndex = el.key - 1
}
}
if (el.key % 1 == 0) {
choicesnew[el.key - 1] = {
value: el.value,
key: el.key,
choices: []
}
} else {
choicesnew[Math.trunc(el.key) - 1]['choices'].push({
value: el.value,
key: el.key,
field: element.field
})
}
});
fieldinfoNew[element.field] = ({
choices: choicesnew,
field: element.field,
title: element.title,
type: element.type,
popupwindow: element.popupwindow,
required: element.required,
})
return
}
fieldinfoNew[element.field] = ({
choices,
field: element.field,
title: element.title,
unit: element.unit,
type: element.type,
placeholder: element.placeholder,
popupwindow: element.popupwindow,
required: element.required,
})
});
}
if (data.info.floor != null) data.info.floor = data.info.floor != 0 ? data.info.floor + '楼' : null
if (data.type == "edit") this.data.contactInformationState = data.info.iswechattype
else data.info.iswechattype = 0
if (data.info.leasetime == 0) data.info.leasetime = '随时'
else if (data.info.leasetime && data.info.leasetime.length > 2) {
let leasetimeTime = new Date(data.info.leasetime)
this.data.pitchyear = leasetimeTime.getFullYear()
this.data.pitchmonth = leasetimeTime.getMonth() + 1
this.data.pitchday = leasetimeTime.getDate()
}
if (data.info.rentalduration == 0) data.info.rentalduration = '不限租期'
if (data.info.rent == 0) data.info.rent = data.info.rent.toString()
if (data.info.floor != null) this.data.floorValue = [parseInt(data.info.floor) < 0 ? parseInt(data.info.floor) + 3 : parseInt(data.info.floor) + 2]
if (data.info.school != null) this.data.nearSchoolList = data.info.school
if (locationhead != "") data.info.location = `${locationhead}>>${locationtail}`
// 将发布者身份 放到最前面
data.fieldinfo['status'] = [data.fieldinfo['identity'][1]] || []
data.fieldinfo['identity'].splice(1, 1)
this.setData({
id: data.id,
fieldinfo: data.fieldinfo,
offshelftime: data.offshelftime,
updatetime: data.updatetime,
timestamp: data.timestamp,
fieldinfoNew,
newcity: data.city,
newinfo: data.info,
newToken: data.token,
imgs: data.info.images,
videos: data.info.video,
publishingrules: data.publishingrules,
floorValue: this.data.floorValue,
nearSchoolList: this.data.nearSchoolList,
newtype: data.type,
newStatus: data.status,
contactInformationState: this.data.contactInformationState,
leaseTimeValue: this.data.leaseTimeValue,
areaRegionIndex: this.data.areaRegionIndex,
unfoldState: data.isrules == 1 ? true : false,
pitchyear: this.data.pitchyear,
pitchmonth: this.data.pitchmonth,
pitchday: this.data.pitchday,
allowpublishednum: data.allowpublishednum,
intermediaryVlaue: data.intermediary,
uploadData: data.uploadData,
})
wx.hideLoading()
if (this.data.types == 'plus') this.firstStepPopover()
}).catch(() => {
this.setData({
loding: false
})
})
},
// 初始化弹出的窗口
firstStepPopover() {
// return
let field = 'type'
let step = 0
let it = 'basic'
// let field = 'intermediary'
// let step = 0
// let it = 'status'
let popUpIs = ""
let popUpStepState = ""
this.data.aa.forEach(element => {
if (this.data.fieldinfo['status'][0]['field'] == element['field']) {
popUpIs = element.popUpIs
popUpStepState = element.popUpStepState
}
});
this.setData({
step,
popUpIs,
popUpdate: this.data.fieldinfoNew[field],
popUpit: it,
popUpStepState
})
},
/**
* 生命周期函数--监听页面显示
*/
aaaaa: 0,
onShow: function () {
// 在Mac 是获取 地图插件用户选择的地址信息
const location = chooseLocation.getLocation()
// this.setData({
// locationTatx: location
// })
let that = this
if (location) {
that.data.newinfo.latitude = location.latitude
that.data.newinfo.longitude = location.longitude
that.data.newinfo.address = location.name
that.setData({
newinfo: that.data.newinfo,
popUpIs: ""
})
that.getPlaceAround()
// if (that.data.popUpIs == "") {
// that.popUpNextStep()
// }
}
var title = that.data.write_long_textarea;
if (title) {
wx.getStorage({
key: title,
success: function (res) {
if (title == 'aroundSchool') {
that.data.aroundSchoolList[res.data.index].distance = res.data.distance;
that.setData({
aroundSchoolList: that.data.aroundSchoolList
})
} else {
that.data.info[title].value = res.data;
that.setData({
info: that.data.info
})
}
wx.removeStorage({
key: title,
success: function (res) {
that.setData({
write_long_textarea: false
})
},
})
},
})
}
},
onReady: function () {
this.picker = this.selectComponent("#custom-picker")
},
// 输入。。
input: function (e) {
let title = e.currentTarget.dataset.title;
this.data.info[title].value = e.detail.value;
this.setData({
info: this.data.info
})
},
issubmit: false,
// 选择图片
get_img: function () {
var that = this;
let limitSuffix = ['svg'] // 需要限制的后缀数组
wx.chooseImage({
count: 9 - that.data.imgs.length,
sizeType: ['compressed'],
success: (res) => {
let isLt10M = true;
let isSvg = true
var imgList = [];
for (var i = 0; i < res.tempFiles.length; i++) {
var size = res.tempFiles[i].size / 1024 / 1024;
let suffixIndex = res.tempFiles[i].path.lastIndexOf('.')
let suffix = res.tempFiles[i].path.slice(suffixIndex + 1, res.tempFiles[i].path.length)
if (size < 5 && !limitSuffix.includes(suffix.toLowerCase())) {
// 小于3M且照片数量<6的时候才触发上传
// that.data.imgs.push({
// url: data.url,
// aid: data.aid
// })
// that.setData({
// imgs: that.data.imgs
// })
let imgs = this.data.imgs || []
imgs.push({
isImgLoad: true,
path: res.tempFiles[i].path,
progress: 0,
})
this.setData({
imgs,
})
that.upload_picnew(res.tempFiles[i].path, this.data.imgs.length)
} else if (size >= 5) isLt10M = false;
else if (limitSuffix.includes(suffix.toLowerCase())) isSvg = false
}
if (!isLt10M) {
// 存在大于3M的只提示一次
wx.showModal({
title: '提示',
content: '图片大小不能超过5M',
})
} else if (!isSvg) {
wx.showModal({
title: '提示',
content: '上传文件后缀不允许',
})
}
},
fail(err) {
wx.showModal({
title: 'chooseImageErr',
content: err,
})
}
})
},
// 上传图片
upload_picnew: function (imgUrl, index) {
var that = this;
const uploadTask = wx.uploadFile({
url: `https://oss.gter.net/upload`,
filePath: imgUrl,
name: 'files',
formData: {
uniqid: that.data.uniqid,
session: app.globalData.session,
type: "image",
data: this.data.uploadData,
},
header: app.globalData.header,
success: function (res) {
try {
var data = JSON.parse(res.data);
if (data.code == 200) {
data = data.data
if (data.aid > 0) {
// 长度<6个的时候再push
let imgs = that.data.imgs
imgs.forEach((element, index) => {
if (element.path == imgUrl) {
element['isImgLoad'] = false
element['url'] = data.url
element['aid'] = data.aid
}
})
that.setData({
imgs,
})
} else {
wx.showModal({
title: data.state,
icon: 'none'
})
}
} else {
wx.showModal({
title: '提示',
content: data.message
})
}
} catch (e) {
wx.showToast({
title: 'uploadCatch' + e,
icon: 'none'
})
}
},
fail: function (err) {
wx.showModal({
title: 'uploadFileErr',
content: err,
})
}
})
uploadTask.onProgressUpdate(res => {
let imgs = this.data.imgs
// imgs[index - 1]['progress'] = res.progress
imgs.forEach((element, index) => {
if (element.path == imgUrl) element['progress'] = res.progress
})
this.setData({
imgs
})
})
},
// 选择mp4
get_video: function () {
let that = this;
wx.chooseMedia({
count: 3 - that.data.videos.length,
mediaType: ['video'],
success: function (res) {
let isSize5M = false
let tempFiles = res.tempFiles
tempFiles.forEach(element => {
var size = element.size / 1024 / 1024;
if (size > 5) isSize5M = true
else that.upload_videonew(element.tempFilePath)
})
if (isSize5M) {
wx.showModal({
title: '提示',
content: '视频大小不能超过5M',
})
}
}
})
},
// 上传mp4
upload_videonew: function (videoUrl) {
var that = this;
wx.showLoading({
title: '视频上传中',
})
const uploadTask = wx.uploadFile({
url: `https://oss.gter.net/upload`,
filePath: videoUrl,
name: 'files',
formData: {
uniqid: that.data.uniqid,
session: app.globalData.session,
type: 'video',
data: this.data.uploadData,
},
header: app.globalData.header,
success: function (res) {
try {
let re = JSON.parse(res.data)
if (re.code == 200) {
let data = re.data
that.data.videos.push({
url: data.url,
aid: data.aid
})
that.setData({
videos: that.data.videos
})
} else {
wx.showModal({
title: '提示',
content: re.message
})
}
} catch (e) {
wx.showToast({
title: 'uploadVideoCatch' + e,
icon: 'none'
})
}
},
fail: function (err) {
wx.showModal({
title: 'uploadVideoErr',
content: err,
})
},
complete(res) {
wx.hideLoading()
}
})
},
// 删除图片 和 视频
del_pic: function (e) {
let {
index,
box
} = e.currentTarget.dataset;
if (box == 'img') {
let aid = this.data.imgs[index]['aid']
if (aid == this.data.newinfo['aid']) this.data.newinfo['aid'] = ""
this.data.imgs.splice(index, 1)
this.setData({
imgs: this.data.imgs
})
} else {
this.data.videos.splice(index, 1)
this.setData({
videos: this.data.videos
})
}
},
wxParseTagATap: function (e) {
var url = e.currentTarget.dataset.src;
wx.navigateTo({
url: url,
})
},
changeInputSelect() {},
// 切换发布须知的状态
cutUnfoldState() {
this.setData({
unfoldState: !this.data.unfoldState
})
},
// 跳转我要申述
goAppeal() {
wx.redirectTo({
url: '/pages/appeal/appeal?appealtoken=' + this.data.appealtoken,
})
},
// 跳转我的-发布
goUser() {
wx.redirectTo({
url: '/pages/user/user?tab=publish',
})
},
// 点击关闭
triggerRulesClose() {
wx.redirectTo({
url: '/pages/user/user?tab=publish',
})
},
// 微信号有wxid_ 时弹窗的关闭
WechatIDClose() {
this.setData({
triggerRules: 0
})
},
// 点击规则4中的图片预览
methodPreview() {
wx.previewImage({
urls: ["https://oss.gter.net/attachment/Zvt57TuJSUvkyhw-xG7Y2l-T_pIqc3nqqsgFptxhXa6RWi26P-BuTQdCF7eV7tkb8MVYZjQ0Mjk~"],
current: "https://oss.gter.net/attachment/Zvt57TuJSUvkyhw-xG7Y2l-T_pIqc3nqqsgFptxhXa6RWi26P-BuTQdCF7eV7tkb8MVYZjQ0Mjk~"
})
},
bindChange: function (e) {
const val = e.detail.value
this.setData({
leaseTimeValue: val,
['newinfo.rentalduration']: this.data.fieldinfoNew['rentalduration'].choices[1].choices[val].value
})
},
bindChange1: function (e) {
const val = e.detail.value
this.setData({
floorValue: val,
['newinfo.floor']: this.data.floorValue - 2 + '楼'
})
},
// 点击附近学校的添加学校
nearSchoolAdd() {
this.data.nearSchoolList.push({
name: '',
distance: ""
})
this.setData({
nearSchoolList: this.data.nearSchoolList
})
},
// 点击附近学校的删除学校
del_nearSchool(e) {
let index = e.currentTarget.dataset.index
this.data.nearSchoolList.splice(index, 1)
this.setData({
nearSchoolList: this.data.nearSchoolList
})
},
// 附近学校的输入绑定数据
nearSchoolInput(e) {
let value = e.detail.value
let {
index,
name
} = e.target.dataset
this.data.nearSchoolList[index][name] = value
this.setData({
nearSchoolList: this.data.nearSchoolList
})
},
// 联系方式中微信的切换状态
contactInformationwechatcut(e) {
let state = e.currentTarget.dataset.state
if (state == 1) { // 选择填写微信号
this.data.newinfo['wechatdata'] = {
aid: 0,
url: null
}
this.data.newinfo.iswechattype = 1
} else if (state == 0) { // 回复默认
this.data.newinfo['wechatdata'] = {
aid: 0,
url: null
}
this.data.newinfo['wechat'] = null
this.data.newinfo['iswechattype'] = 0
}
this.setData({
contactInformationState: state
})
},
// 计算起租日期
calculateOfDate() {
let newyear = time.getFullYear()
let newmonth = time.getMonth() + 1 // 现在的月份
let list = []
for (let i = 0; i < 24; i++) {
let week = (new Date(newyear, newmonth - 1, 1).getDay())
newmonth = newmonth.toString().padStart(2, 0)
let monthDayCount = this.getCountDays(`${newyear}-${newmonth}`)
newmonth++
list.push({
week,
monthDayCount,
name: newmonth - 1 == 0 ? `${newyear - 1}${12}` : `${newyear}${newmonth - 1}`,
year: newyear,
month: newmonth - 1,
})
if (newmonth == 13) {
newyear++
newmonth = 1
}
}
this.setData({
calculateOfDateList: list,
calculateOfDateTime: {
year: new Date().getFullYear(),
month: new Date().getMonth() + 1,
day: new Date().getDate()
}
})
},
// 返回当前月份的天数
getCountDays(time) {
var curDate = new Date(time);
var curMonth = curDate.getMonth() + 1;
curDate.setMonth(curMonth);
curDate.setDate(0);
return curDate.getDate();
},
// 点击选择日期
selectOfDate(e) {
let {
year,
month,
day
} = e.target.dataset
this.data.newinfo.leasetime = `${year}-${month.toString().padStart(2, 0)}-${day.toString().padStart(2, 0)}`
this.setData({
pitchyear: year,
pitchmonth: month,
pitchday: day,
newinfo: this.data.newinfo
})
this.data.step = this.data.step - 1
setTimeout(() => {
this.popUpNextStep()
}, 500);
},
// 点击操作弹出弹窗
clickOption(e) {
let {
field,
step,
it
} = e.currentTarget.dataset
let popUpIs = ""
let popUpStepState = ""
if (this.data.fieldinfo[it][step].popupwindow == 0) return
this.data.aa.forEach(element => {
if (this.data.fieldinfo[it][step]['field'] == element['field']) {
popUpIs = element.popUpIs
popUpStepState = element.popUpStepState
}
});
if (popUpIs == 'nearSchool') {
this.data.nearSchoolList.push({
name: '',
distance: ""
})
this.setData({
nearSchoolList: this.data.nearSchoolList
})
}
if (field == 'address') {
if (this.data.fieldinfoNew.address.type == 'map') popUpIs = "AddressHongKong"
}
if (popUpIs == 'unilineInput' || popUpIs == 'multilineInput' || popUpIs == 'multilineInput1') this.data.focustitle = field
this.setData({
step,
popUpIs,
popUpdate: this.data.fieldinfoNew[field],
popUpit: it,
popUpStepState,
focustitle: this.data.focustitle
})
},
// 选择弹窗选项
selectOption(e) {
let {
choices,
key,
value,
field
} = ""
if (e.currentTarget) {
choices = e.currentTarget.dataset.choices
key = e.currentTarget.dataset.key
value = e.currentTarget.dataset.value
field = e.currentTarget.dataset.field
} else field = e
if (field == "intermediary" && value == "求房源" && this.data.types == 'plus') {
wx.navigateTo({
url: `/pages/askHousing/askHousing?uniqid=${this.data.uniqid}`,
})
return
}
let popUpSubtitle1 = this.data.popUpSubtitle
let popUpIs = ""
let popUpTitle = ""
let popUpStepState = ""
let popUpSubtitle = ""
if (choices) {
popUpSubtitle = value
this.setData({
popUpdate: {
choices
},
})
} else {
// 选择出租方式后需要 >> 显示
if (this.data.fieldinfo[this.data.popUpit][this.data.step].field == 'type') {
this.setData({
step: this.data.step + 1,
popUpdate: this.data.fieldinfo[this.data.popUpit][this.data.step + 1],
[`newinfo.${this.data.fieldinfo[this.data.popUpit][this.data.step].field}`]: popUpSubtitle1 + '>>' + value
})
} else if (this.data.fieldinfo[this.data.popUpit][this.data.step].field == 'leasetime' && value != '随时') {
this.setData({
step: this.data.step + 1,
})
} else {
this.setData({
step: this.data.step + 1,
popUpdate: this.data.fieldinfo[this.data.popUpit][this.data.step + 1],
[`newinfo.${this.data.fieldinfo[this.data.popUpit][this.data.step].field}`]: value
})
}
}
if (field == "type" && this.typetouList.includes(value)) {
popUpTitle = this.data.info['type']['name']
if (this.data.popUpdate['choices'].length >= 5) popUpIs = "twoLines"
else popUpIs = "AListOF"
popUpStepState = 1
}
if (field == 'rentalduration' && value == this.data.fieldinfo[this.data.popUpit][this.data.step]['placeholder']) {
popUpTitle = this.data.info['rentalduration']['name']
popUpIs = "leaseTime"
popUpStepState = 2
}
if (field == 'leasetime' && value != "随时") {
popUpTitle = this.data.info['leasetime']['name']
popUpIs = "ofDate"
popUpStepState = 1
}
if (popUpIs == "") {
if (this.data.fieldinfo[this.data.popUpit].length == this.data.step && this.data.popUpOrder.indexOf(this.data.popUpit) != -1) {
this.data.popUpit = this.data.popUpOrder[this.data.popUpOrder.indexOf(this.data.popUpit) + 1]
this.data.step = 0
}
this.data.aa.forEach(element => {
if (this.data.fieldinfo[this.data.popUpit][this.data.step]['field'] == element['field']) {
let field = this.data.fieldinfo[this.data.popUpit][this.data.step].field
if (field == 'video') {
if (this.data.videos.length > 0) {
this.setData({
popUpIs: ""
})
return
}
} else if (this.data.newinfo[field] != null && this.data.newinfo[field] != "") {
this.setData({
popUpIs: ""
})
return
}
this.optionScroll(field)
popUpIs = element.popUpIs
popUpTitle = this.data.fieldinfo[this.data.popUpit][this.data.step].title
popUpStepState = element.popUpStepState
if (popUpIs == 'unilineInput' || popUpIs == 'multilineInput' || popUpIs == 'multilineInput1') {
this.data.focustitle = this.data.fieldinfo[this.data.popUpit][this.data.step].field
}
this.setData({
popUpdate: this.data.fieldinfoNew[this.data.fieldinfo[this.data.popUpit][this.data.step].field],
focustitle: this.data.focustitle
})
}
});
}
if (popUpIs == 'nearSchool') {
this.data.nearSchoolList.push({
name: '',
distance: ""
})
this.setData({
nearSchoolList: this.data.nearSchoolList
})
}
if (popUpIs == 'ofDate' && this.data.newinfo.leasetime == null) {
let calculateOfDateList = this.data.calculateOfDateList[0]
this.data.newinfo.leasetime = calculateOfDateList.year + '-' + calculateOfDateList.month + '-' + new Date().getDate()
}
this.setData({
popUpSubtitle,
popUpTitle,
popUpIs,
popUpStepState
})
},
// 弹出上角的关闭弹窗
closePopUp() {
try {
let currentField = this.data.fieldinfo[this.data.popUpit][this.data.step].field
if (currentField == 'school') {
this.data.nearSchoolList.forEach((element, index) => {
if (element.name == "") this.data.nearSchoolList.splice(index, 1)
})
this.setData({
nearSchoolList: this.data.nearSchoolList
})
}
if (this.data.newinfo.leasetime == "选择日期") this.data.newinfo.leasetime = ""
if (this.data.popUpIs == 'leaseTime' && currentField == 'rentalduration') {
this.setData({
['newinfo.rentalduration']: this.data.fieldinfoNew['rentalduration'].choices[1].choices[this.data.leaseTimeValue].value
})
}
if (currentField == 'floor') {
this.setData({
['newinfo.floor']: this.data.floorValue - 2 > 0 ? this.data.floorValue - 2 + '楼' : this.data.floorValue - 3 + '楼'
})
}
this.setData({
popUpIs: "",
popUpit: "",
popUpSubtitle: "",
newinfo: this.data.newinfo,
residentialPopSelectState: false,
residentialPopFillState: false,
})
} catch (error) {
this.setData({
popUpIs: "",
popUpit: "",
popUpSubtitle: "",
newinfo: this.data.newinfo,
residentialPopSelectState: false,
residentialPopFillState: false,
})
}
},
// 填好了
fillThe() {
let currentField = 'subject'
if (this.data.fieldinfoNew[currentField].required == 1 && (this.data.newinfo[currentField] == null || this.data.newinfo[currentField] == "")) {
wx.showToast({
title: `请填写${this.data.fieldinfoNew[currentField].title}`,
icon: 'none'
})
return
}
this.setData({
popUpIs: "",
popUpit: "",
popUpSubtitle: "",
})
},
// 弹窗右上角的跳过
popUpSkip(e) {
let currentFieldinfo = this.data.fieldinfo[this.data.popUpit][this.data.step] // 当前步数的 fieldinfo 数据
// 在 学校弹窗 跳过时需要 验证是否有填学校名称,没有填则删除数据
if (currentFieldinfo.field == 'school') {
for (var i = 0; i < this.data.nearSchoolList.length; i++) {
if (this.data.nearSchoolList[i].name == '') {
this.data.nearSchoolList.splice(i, 1)
i--
}
}
this.setData({
nearSchoolList: this.data.nearSchoolList
})
}
this.data.step = this.data.step + 1
if (this.data.fieldinfo[this.data.popUpit].length == this.data.step && this.data.popUpOrder.indexOf(this.data.popUpit) != -1) {
this.data.popUpit = this.data.popUpOrder[this.data.popUpOrder.indexOf(this.data.popUpit) + 1]
this.data.step = 0
}
let nextfield = this.data.fieldinfo[this.data.popUpit][this.data.step].field
if (this.data.newinfo[nextfield] != null && this.data.newinfo[nextfield] != "") {
this.setData({
popUpIs: "",
residentialPopSelectState: false,
residentialPopFillState: false,
})
return
}
this.data.aa.forEach(element => {
if (this.data.fieldinfo[this.data.popUpit][this.data.step]['field'] == element['field']) {
if (element.popUpIs == 'nearSchool') {
this.data.nearSchoolList.push({
name: '',
distance: ""
})
this.setData({
nearSchoolList: this.data.nearSchoolList
})
}
this.optionScroll(this.data.fieldinfo[this.data.popUpit][this.data.step].field)
this.setData({
popUpIs: element.popUpIs,
popUpTitle: this.data.fieldinfo[this.data.popUpit][this.data.step].title,
popUpdate: this.data.fieldinfoNew[this.data.fieldinfo[this.data.popUpit][this.data.step].field],
popUpStepState: element.popUpStepState,
residentialPopSelectState: false,
residentialPopFillState: false,
})
}
});
},
// 下一步
popUpNextStep(e) {
let currentField = this.data.fieldinfo[this.data.popUpit][this.data.step].field
let popUpIs = ""
if (currentField == 'images' && !this.data.newinfo['aid'] && this.data.newinfo['images'] && this.data.newinfo['images'].length > 1) {
wx.showToast({
icon: "none",
title: '请选择封面',
})
return
}
// 下一步是附近学校时 判断学校名是否为空 空则删除对应学校数据
if (currentField == 'school') {
for (var i = 0; i < this.data.nearSchoolList.length; i++) {
if (this.data.nearSchoolList[i].name == '') {
this.data.nearSchoolList.splice(i, 1)
i--
}
}
this.setData({
nearSchoolList: this.data.nearSchoolList
})
}
// 出租时长
if (currentField == 'rentalduration') {
this.setData({
['newinfo.rentalduration']: this.data.fieldinfoNew['rentalduration'].choices[1].choices[this.data.leaseTimeValue].value
})
}
// 楼层
if (currentField == 'floor') {
this.setData({
['newinfo.floor']: this.data.floorValue - 2 > 0 ? this.data.floorValue - 2 + '楼' : this.data.floorValue - 3 + '楼'
})
}
// 判断当前弹窗是否是必填项 再判断是否有填写数据,有执行下一步
if (this.data.fieldinfoNew[currentField].required == 1 && (this.data.newinfo[currentField] == null || this.data.newinfo[currentField] == "" || this.data.newinfo[currentField] == undefined)) {
wx.showToast({
title: `${currentField == 'scholl' ? '请设置' : currentField =='message' ? '请填写' : currentField =='introduction' ?'请填写' :currentField =='rent'?'请填写' :'请选择' }${this.data.fieldinfoNew[currentField].title}`,
icon: 'none'
})
return
}
// 判断联系方式选填其中一项 都没有则弹出提示
if (currentField == 'wechat') {
let newinfo = this.data.newinfo
if ((newinfo.tel == null || newinfo.tel == "") && (newinfo.wechat == null || newinfo.wechat == "") && (newinfo['wechatdata']['aid'] == 0) && (newinfo.whatsapp == null || newinfo.whatsapp == "")) {
wx.showToast({
title: `请填写联系方式`,
icon: 'none'
})
return
}
}
if (this.data.fieldinfo[this.data.popUpit][this.data.step].title == '微信' || this.data.fieldinfo[this.data.popUpit][this.data.step].title == 'WhatsApp' || this.data.fieldinfo[this.data.popUpit][this.data.step].title == '电话号码') {
this.data.popUpit = this.data.popUpOrder[this.data.popUpOrder.indexOf(this.data.popUpit) + 1]
this.data.step = -1
}
// 步数加一
this.setData({
step: this.data.step + 1
})
if (this.data.fieldinfo[this.data.popUpit].length == this.data.step && this.data.popUpOrder.indexOf(this.data.popUpit) != -1) {
this.data.popUpit = this.data.popUpOrder[this.data.popUpOrder.indexOf(this.data.popUpit) + 1]
this.data.step = 0
}
// 判断下一步是否有值,有则隐藏弹窗
let nextfield = this.data.fieldinfo[this.data.popUpit][this.data.step].field
// 判断下一步学校是否有值原因是school值没有直接放在 nextfield 里,需要特殊处理
if (nextfield == 'school' && this.data.nearSchoolList.length != 0) {
this.setData({
popUpIs: "",
popUpSubtitle: "",
})
return
}
// 判断下一步联系方式是否有值,原因联系方式弹窗不只一个,需要特殊处理
if (nextfield == 'wechat' && ((this.data.newinfo['tel'] != null && this.data.newinfo['tel'] != '') || (this.data.newinfo['whatsapp'] != null && this.data.newinfo['whatsapp'] != '') || (this.data.newinfo['wechatdata'] && this.data.newinfo['wechatdata'].aid != 0))) {
this.setData({
popUpIs: "",
popUpSubtitle: ""
})
return
}
// 这是判断下一步是否有值的总处理
if (this.data.newinfo[nextfield] != null && this.data.newinfo[nextfield] != "") {
this.setData({
popUpIs: "",
popUpSubtitle: "",
residentialPopSelectState: false,
residentialPopFillState: false,
})
return
}
this.data.aa.forEach(element => {
if (this.data.fieldinfo[this.data.popUpit][this.data.step]['field'] == element['field']) {
// 附近学校没有数据时加一个默认数据
if (element.popUpIs == 'nearSchool' && this.data.nearSchoolList.length == 0) {
this.data.nearSchoolList.push({
name: '',
distance: ""
})
}
// 因为 field == 'address' 分香港和非香港地区 这个是香港地区的 地址调用地图API
if (this.data.fieldinfoNew[this.data.fieldinfo[this.data.popUpit][this.data.step].field].field == 'address') {
if (this.data.fieldinfoNew.address.type == 'map') {
element.popUpIs = "AddressHongKong"
}
}
if (this.data.types.indexOf('edit') > -1 && this.data.fieldinfo[this.data.popUpit][this.data.step].popupwindow == 0) {
this.setData({
popUpIs: ""
})
return
}
this.optionScroll(this.data.fieldinfoNew[this.data.fieldinfo[this.data.popUpit][this.data.step].field].field)
if (element.popUpIs == 'unilineInput' || element.popUpIs == 'multilineInput' || element.popUpIs == 'multilineInput1') {
this.data.focustitle = this.data.fieldinfo[this.data.popUpit][this.data.step].field
}
this.setData({
popUpdate: this.data.fieldinfoNew[this.data.fieldinfo[this.data.popUpit][this.data.step].field],
popUpIs: element.popUpIs,
popUpStepState: element.popUpStepState,
popUpTitle: this.data.fieldinfo[this.data.popUpit][this.data.step].title,
popUpSubtitle: "",
nearSchoolList: this.data.nearSchoolList,
focustitle: this.data.focustitle,
residentialPopSelectState: false,
residentialPopFillState: false,
})
}
});
},
// 单行输入框的输入
popUpInput(e) {
let value = e.detail.value
let field = e.currentTarget.dataset['field']
if (field == 'introduction') value = value.substr(0, 500)
else if (field == 'address') value = value.substr(0, 100)
else if (field == 'subject') value = value.substr(0, 80)
this.setData({
[`newinfo.${e.currentTarget.dataset.field}`]: value
})
},
popUpInput1(e) {
let value = e.detail.value
value = value.substr(0, 500)
this.setData({
[`newinfo.message`]: value
})
},
// 点击 弹窗-单行输入框 里的完成, 获取数据并下一步
popUpconfirm(e) {
let value = e.detail.value
let {
field,
popupit
} = e.currentTarget.dataset
this.setData({
[`newinfo.${field}`]: value
})
this.popUpNextStep()
},
modification(e) {
this.setData({
popUpIs: 'nearSchool',
popUpdate: this.data.fieldinfoNew['school'],
popUpit: 'address',
step: e.currentTarget.dataset.step,
popUpStepState: 2
})
},
// 新的发布
NewRelease(e) {
// 判断微信号里有没有wxid_
if (this.data.newinfo.wechat && this.data.newinfo.wechat.indexOf('wxid_') == 0) {
this.setData({
triggerRules: 4
})
return
}
if (this.issubmit) {
wx.showToast({
title: '请勿重复提交~',
icon: 'none'
})
return false
}
this.issubmit = true
wx.showLoading({
title: '提交中...'
})
let status = e.currentTarget.dataset.status
let fieldinfoNew = this.data.fieldinfoNew
let fieldinfo = this.data.fieldinfo
// 所在楼层
if (status == 0 && this.data.popUpIs == 'floor') {
this.data.newinfo.floor = this.data.floorValue[0] - 2 > 0 ? this.data.floorValue[0] - 2 + '楼' : this.data.floorValue[0] - 3 + '楼'
}
if (this.data.newinfo && this.data.newinfo.subject) {
this.data.newinfo.subject = this.data.newinfo.subject.trim()
}
// 下面验证需要提交的数据,...解决浅拷贝问题
let newinfo = {
...this.data.newinfo
}
newinfo.images = this.data.imgs
newinfo.video = this.data.videos
newinfo.floor = parseInt(newinfo.floor) // floor数据加了子需要转正整数
if (newinfo.acreage != null && newinfo.acreage != "") newinfo.acreage = Number(newinfo.acreage)
if (newinfo.latitude) newinfo['point'] = [newinfo.latitude, newinfo.longitude]
// 判断附近学校是否为空
if (this.data.nearSchoolList.length > 0) {
for (var i = 0; i < this.data.nearSchoolList.length; i++) {
if (this.data.nearSchoolList[i].name == '') {
this.data.nearSchoolList.splice(i, 1)
i--
}
}
this.setData({
nearSchoolList: this.data.nearSchoolList
})
}
newinfo.school = this.data.nearSchoolList
if (newinfo.rentalduration == '不限租期') newinfo.rentalduration = 0
if (newinfo.leasetime == '随时') newinfo.leasetime = 0
for (const key in fieldinfo) {
fieldinfo[key].forEach(element => {
if (!element) return
// 出租方式
if (element.field == "type") {
this.data.fieldinfoNew[element.field].choices.forEach(el => {
el.choices.forEach(e => {
if (newinfo.type && newinfo.type.indexOf(e.value) >= 0) newinfo.type = e.key
})
})
}
// 出租时长
if (element.field == "rentalduration") {
element.choices.forEach(res => {
if (res.value == newinfo.rentalduration) newinfo.rentalduration = res.key
})
}
// 电梯 晾晒区
if (element.field == "elevator" || element.field == 'sunshinearea') {
element.choices.forEach(res => {
if (res.value == newinfo[element.field]) newinfo[element.field] = res.key
})
}
// 房屋类型
if (element.field == "property") {
element.choices.forEach(res => {
if (res.value == newinfo.property) newinfo.property = res.key
})
}
// 性别
if (element.field == "gender") {
element.choices.forEach((el, index) => {
if (el.value == newinfo.gender) newinfo.gender = index + 1
})
}
// 发布者身份
if (element.field == 'intermediary') {
element.choices.forEach((el, index) => {
if (el.value == newinfo.intermediary) newinfo.intermediary = el.key
})
}
// 所在区域
if (element.field == 'location') {
this.data.fieldinfoNew[element.field].choices.forEach(el => {
el.choices.forEach(e => {
if (newinfo.location && newinfo.location.indexOf(e.value) >= 0) newinfo.location = e.key
})
})
}
})
}
let intermediaryVlaue = this.data.intermediaryVlaue
newinfo['intermediary'] = intermediaryVlaue
miucms.request(app.globalData.baseURL + '/tenement/v2/api/publish/submit', {
info: newinfo,
token: this.data.newToken,
status
}).then(res => {
this.issubmit = false
if (res.code == 200) {
if (status == 0) {
wx.redirectTo({
url: '/pages/user/user?tab=publish',
})
} else {
if (res.data['uniqid']) this.data.uniqid = res.data['uniqid']
let uniqid = this.data.uniqid
// 计算弹出哪个 提示认证框的
let intermediary = app.globalData.user.intermediary
let popUpIs = ""
if ((intermediaryVlaue == 1 && intermediary == 1) || this.data.verified == 1) {
popUpIs = "intermediary-voluntarily-succeed-pop"
setInterval(() => {
this.setData({
countDown: this.data.countDown - 1
})
}, 1000);
setTimeout(() => {
wx.redirectTo({
url: '/pages/show/show?uniqid=' + uniqid,
})
}, 2000);
} else popUpIs = "intermediary-succeed-pop"
this.setData({
popUpIs
})
}
}
if (res.code == 201) {
if (res.data && (res.data.rule == 1 || res.data.rule == 2 || res.data.rule == 3 || res.data.rule == 4)) {
this.setData({
triggerRules: res.data.rule,
appealtoken: res.data.appealtoken
})
wx.hideLoading()
return
}
wx.showModal({
title: '提示',
content: res.message
})
if (res.data.type == 'field') {
if (res.data && res.data.field != 'rent') {
for (const key in this.data.fieldinfo) {
this.data.fieldinfo[key].forEach(el => {
if (el.field == res.data.field) {
wx.pageScrollTo({
selector: `.clickInput${res.data.field}`,
offsetTop: -200
})
}
})
}
}
this.calculateTargetPopup(res.data.field)
}
}
wx.hideLoading()
}).catch(err => {
this.issubmit = false
wx.hideLoading()
})
},
// 点击所在区域的左边
clickAreaRegion(e) {
let index = e.currentTarget.dataset.index
this.setData({
areaRegionIndex: index
})
},
// 点击所在区域的右边
clickAreaDistrict(e) {
let {
value,
key,
field
} = e.currentTarget.dataset
this.data.newinfo[field] = this.data.fieldinfoNew[field].choices[this.data.areaRegionIndex].value + '>>' + value
this.setData({
newinfo: this.data.newinfo
})
this.popUpNextStep()
},
chooseLocation: function (e) {
let that = this
// 因为 PC端 不能使用 wx.chooseLocation 组件,需要判断打开地图插件还是组件
if (this.data.isPC) this.choosel()
else {
let newinfo = this.data.newinfo
let latitude = newinfo['latitude']
let longitude = newinfo['longitude']
if (newinfo.location && !latitude) {
this.data.fieldinfoNew["location"].choices.forEach(el => {
el.choices.forEach(e => {
if (newinfo.location && newinfo.location.indexOf(e.value) >= 0) {
let longitudeLatitude = this.data.longitudeLatitude
latitude = longitudeLatitude[(e.key >>> 0) || 1]['n']
longitude = longitudeLatitude[(e.key >>> 0) || 1]['e']
}
})
})
}
if (!latitude) latitude = 22.297759
if (!longitude) longitude = 114.179495
wx.chooseLocation({
latitude: latitude || 22.297759,
longitude: longitude || 114.179495,
success: function (e) {
that.data.newinfo.latitude = e.latitude
that.data.newinfo.longitude = e.longitude
that.data.newinfo.address = e.name
that.setData({
newinfo: that.data.newinfo,
popUpIs: ""
})
that.getPlaceAround()
// if (that.data.popUpIs == "") that.popUpNextStep()
},
fail: () => {
//未打开定位
wx.getSetting({
success: (res) => {
// 打开设置界面
if (!res.authSetting['scope.userLocation']) wx.openSetting({})
}
})
}
})
}
},
// 上传二维码
UploadQRCode() {
let that = this
wx.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album'],
success: function (res) {
let size = res.tempFiles[0].size / 1024 / 1024
if (size > 10) return
let path = res.tempFiles[0].path
wx.showLoading({
title: '上传中...'
})
// 开始上传二维码
that.UploadQRCodeSend(path)
}
})
},
// 上传二维码
UploadQRCodeSend(imgUrl) {
let that = this
const uploadTask = wx.uploadFile({
// url: `${app.globalData.baseURL}/tenement/v2/api/publish/uploadweixinqrcode`,
url: `https://oss.gter.net/upload/qrcode`,
filePath: imgUrl,
name: 'files',
formData: {
// uniqid: that.data.uniqid,
// session: app.globalData.session,
// type,
data: this.data.uploadData,
},
header: app.globalData.header,
success: function (res) {
var res = JSON.parse(res.data);
if (res.code == 200) {
that.setData({
['newinfo.wechatdata.url']: res.data.url,
['newinfo.wechatdata.aid']: res.data.aid,
['newinfo.wechatdata.image']: res.data.image,
['newinfo.iswechattype']: 2,
contactInformationState: 2
})
wx.showToast({
title: '上传成功',
})
} else {
wx.showModal({
title: '提示',
content: res.message
})
}
wx.hideLoading()
},
fail: err => {
wx.hideLoading()
}
})
},
// 用户提交后返回没有填写字段需要弹出字段窗
calculateTargetPopup(field) {
let fieldinfo = this.data.fieldinfo
for (const key in fieldinfo) {
fieldinfo[key].forEach((element, index) => {
if (element.field == field) {
this.data.aa.forEach(el => {
if (el['field'] == element['field']) {
this.setData({
popUpIs: el.popUpIs,
popUpTitle: this.data.fieldinfo[key][index].title,
popUpdate: this.data.fieldinfoNew[this.data.fieldinfo[key][index].field],
step: index,
popUpit: key,
popUpStepState: el.popUpStepState
})
}
})
}
})
}
},
// 检查输入的微信号是否是 wxid_开头的
microSignalCheck() {
if (this.data.newinfo.wechat && this.data.newinfo.wechat.indexOf('wxid_') == 0) {
this.setData({
triggerRules: 4,
popUpIs: ""
})
}
},
// 选项滚动
optionScroll(field) {
// 月租和面积不滚动,原因是当用户弹出月租弹窗图层是同时获取焦点的,这样会把焦点一起滚动
if (field == "rent" || field == "acreage") return
for (const key in this.data.fieldinfo) {
this.data.fieldinfo[key].forEach(el => {
if (el.field == field) {
wx.pageScrollTo({
selector: `.clickInput${field}`,
offsetTop: -200
})
}
})
}
},
bindfocusfocus() {
if (!this.data.isPC) {
this.setData({
focusState: true
})
}
},
bindblurblur() {
this.setData({
focusState: false
})
},
setValue(e) {
let key = e.currentTarget.dataset['key'] || (e.detail.currentTarget && e.detail.currentTarget.dataset['key'])
let value = e.currentTarget.dataset['value'] || (e.detail.currentTarget && e.detail.currentTarget.dataset['value'])
let status = e.currentTarget.dataset['status'] || (e.detail.currentTarget && e.detail.currentTarget.dataset['status'])
if (status == 'boolean' && value == "false") value = false
else if (status == 'boolean' && value == "true") value = true
this.setData({
[key]: value
})
},
// 禁止用户滚动,原因是有可能输入框会被用户滚走
handScroll() {
return
},
// 公共跳转
publicJumps(e) {
let url = e.currentTarget.dataset.url
wx.navigateTo({
url,
})
},
// 跳转详情页面
goShowPage() {
wx.redirectTo({
url: `/pages/show/show?uniqid=${ this.data.uniqid }`,
})
},
popUpIsQRCodeState: false,
handleWechatQRCodeState() {
this.setData({
getWechatQRCodeState: !this.data.getWechatQRCodeState
})
if (this.data.popUpIs) {
this.popUpIsQRCodeState = true
this.setData({
popUpIs: ""
})
}
if (!this.data.getWechatQRCodeState && this.popUpIsQRCodeState) {
this.popUpIsQRCodeState = false
this.setData({
popUpIs: "contactInformation"
})
}
},
// 获取附近小区数据
getPlaceAround() {
if (this.data.placeAroundData.length != 0) {
this.setData({
residentialPopSelectState: true,
step: 1,
popUpit: "address"
})
return
}
miucms.request(`${app.globalData.baseURL}/tenement/v2/api/publish/placeAround`, {
location: `${this.data.newinfo.latitude},${this.data.newinfo.longitude}`
}).then(res => {
if (res.code != 200) {
this.setData({
residentialPopFillState: true
})
return
}
let data = res.data
this.setData({
placeAroundData: data
})
if (data.length > 0) {
this.setData({
residentialPopSelectState: true,
step: 1,
popUpit: "address"
})
}
})
},
// 选择所属小区
selectCommunity(e) {
let id = e.currentTarget.dataset.id
let name = e.currentTarget.dataset.name
this.data.newinfo['communityid'] = id
this.data.newinfo['communityname'] = name
this.data.popUpIs = 'AddressHongKong'
this.setData({
residentialPopSelectState: false,
newinfo: this.data.newinfo
})
this.popUpNextStep()
},
// 打开所属小区的填写
openResidentialPopFill() {
this.setData({
residentialPopSelectState: false,
residentialPopFillState: true
})
},
// 所属小区的填写输入
residentialinput(e) {
let name = e.detail.value
this.data.newinfo['communityname'] = name
this.data.newinfo['communityid'] = ""
this.setData({
newinfo: this.data.newinfo
})
},
})