2470 lines
83 KiB
JavaScript
2470 lines
83 KiB
JavaScript
// 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 tempFilePath = '';
|
||
var submit = false;
|
||
let mapKey = 'IGSBZ-4B7KX-MOG4O-TN3JQ-KA6M5-32FGO'
|
||
let time = new Date()
|
||
let todayDate = '',
|
||
lastYearDate = '';
|
||
Page({
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
loding: true,
|
||
// address:'',
|
||
isrefusedAuthLocation: 0, //是否拒绝授权地址
|
||
edit: false,
|
||
city: {},
|
||
latitude: '',
|
||
longitude: '',
|
||
info: {
|
||
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: '请填写小区名称'
|
||
},
|
||
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: [],
|
||
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: '0', // 弹窗的 is 默认 0 ,只是去掉初始化时报 null 的警告
|
||
popUpdate: [], // 目标数据
|
||
popUpSubtitle: '',
|
||
popUpStepState: '', // 0是啥都没有 1 是 保存 2 是保存加下一步
|
||
fieldinfoNew: [],
|
||
step: 0, // 步数
|
||
newcity: {},
|
||
aa: {
|
||
type: {
|
||
popUpIs: 'AListOF',
|
||
popUpStepState: 0,
|
||
it: 'basic',
|
||
field: "type"
|
||
},
|
||
rentalduration: {
|
||
// popUpIs: 'AListOF',
|
||
popUpIs: 'leaseTime',
|
||
popUpStepState: 2,
|
||
it: 'basic',
|
||
field: "rentalduration"
|
||
},
|
||
leasetime: {
|
||
popUpIs: 'AListOF',
|
||
popUpStepState: 1,
|
||
it: 'basic',
|
||
field: "leasetime"
|
||
},
|
||
rent: {
|
||
popUpIs: 'rent-budget',
|
||
popUpStepState: 2,
|
||
it: 'basic',
|
||
field: "slider"
|
||
},
|
||
property: {
|
||
popUpIs: 'new-marquee-box',
|
||
popUpStepState: 2,
|
||
it: 'basic',
|
||
field: "property"
|
||
},
|
||
floor: {
|
||
popUpIs: 'new-marquee-box',
|
||
popUpStepState: 2,
|
||
it: 'basic',
|
||
field: "floor"
|
||
},
|
||
elevator: {
|
||
popUpIs: 'AListOF',
|
||
popUpStepState: 1,
|
||
field: "elevator"
|
||
},
|
||
sunshinearea: {
|
||
popUpIs: 'new-marquee-box',
|
||
popUpStepState: 2,
|
||
field: "sunshinearea"
|
||
},
|
||
acreage: {
|
||
popUpIs: 'rent-budget',
|
||
popUpStepState: 2,
|
||
it: 'basic',
|
||
field: "acreage"
|
||
},
|
||
location: {
|
||
popUpIs: 'pop-target-area',
|
||
popUpStepState: 2,
|
||
field: "location"
|
||
},
|
||
gender: {
|
||
popUpIs: 'AListOF',
|
||
popUpStepState: 1,
|
||
field: "gender"
|
||
},
|
||
publishergender: {
|
||
popUpIs: 'AListOF',
|
||
popUpStepState: 1,
|
||
field: "publishergender"
|
||
},
|
||
introduction: {
|
||
popUpIs: 'multilineInput',
|
||
popUpStepState: 2,
|
||
field: "introduction"
|
||
},
|
||
wechat: {
|
||
popUpIs: 'contactInformation',
|
||
popUpStepState: 2,
|
||
field: "wechat"
|
||
},
|
||
subject: {
|
||
popUpIs: 'multilineInput',
|
||
popUpStepState: 3,
|
||
field: "subject"
|
||
},
|
||
|
||
|
||
},
|
||
popUpit: "",
|
||
popUpOrder: ['basic', 'address', 'identity', '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,
|
||
|
||
change: false, // 当两个slider在最右端重合时,将change设置为true,从而隐藏slider2,才能继续操作slider1
|
||
max: 10000, // 两个slider所能达到的最大值
|
||
min: 0, // 两个slider所能取的最小值
|
||
rate: 100, // slider的最大最小值之差和100(或1000)之间的比率
|
||
slider1Max: 10000, // slider1的最大取值
|
||
slider1Value: 0, // slider1的值
|
||
slider2Value: 10000, // slider2的值
|
||
slider2Min: 0, // slider2的最小取值
|
||
slider1W: 100, // slider1的宽度
|
||
slider2W: 0, // slider2的宽度
|
||
leftSliderPriceWidthX: '0%',
|
||
rightSliderPriceWidthX: '0%',
|
||
|
||
aboutRulesList: {}, // 关于发布的数据
|
||
locationObj: {}, // 目标区域的数据
|
||
propertyObj: {}, // 房屋类型的配置数据
|
||
floorObj: {}, // 房屋类型的配置数据
|
||
sunshineareaObj: {}, // 房屋类型的配置数据
|
||
estimatedValue: {
|
||
rent: {
|
||
min: 1000,
|
||
max: 50000,
|
||
rate: 490,
|
||
defaultMin: 50, //
|
||
defaultMax: 80,
|
||
step: 100,
|
||
for: 491
|
||
},
|
||
acreage: {
|
||
min: 100,
|
||
max: 3000,
|
||
rate: 29,
|
||
defaultMin: 5,
|
||
defaultMax: 40,
|
||
step: 10,
|
||
for: 291
|
||
}
|
||
}
|
||
},
|
||
|
||
// 开始滑动
|
||
changeStart: function (e) {
|
||
var idx = parseInt(e.currentTarget.dataset.idx)
|
||
let popUpdate = this.data.popUpdate
|
||
if (idx === 1) {
|
||
// dW是当前操作的slider所能占据的最大宽度百分数
|
||
var dW = (popUpdate.slider2Value - popUpdate.min) / popUpdate.rate
|
||
// var dW = (popUpdate.slider2Value - popUpdate.min) / 490
|
||
this.setData({
|
||
['popUpdate.slider1W']: dW,
|
||
['popUpdate.slider2W']: 100 - dW,
|
||
['popUpdate.slider1Max']: popUpdate.slider2Value,
|
||
['popUpdate.slider2Min']: popUpdate.slider2Value,
|
||
['popUpdate.change']: false
|
||
})
|
||
} else if (idx === 2) {
|
||
var dw = (popUpdate.max - popUpdate.slider1Value) / popUpdate.rate
|
||
// var dw = (popUpdate.max - popUpdate.slider1Value) / 490
|
||
this.setData({
|
||
['popUpdate.slider2W']: dw,
|
||
['popUpdate.slider1W']: 100 - dw,
|
||
['popUpdate.slider1Max']: popUpdate.slider1Value,
|
||
['popUpdate.slider2Min']: popUpdate.slider1Value,
|
||
['popUpdate.change']: false
|
||
})
|
||
}
|
||
},
|
||
|
||
// 正在滑动
|
||
changing: function (e) {
|
||
var idx = parseInt(e.currentTarget.dataset.idx)
|
||
var value = e.detail.value
|
||
let popUpdate = this.data.popUpdate
|
||
let rightSliderPriceWidthX = 100 - (value / popUpdate.max * 100)
|
||
let leftSliderPriceWidthX = value / popUpdate.max * 100
|
||
|
||
if (idx === 1) {
|
||
this.setData({
|
||
['popUpdate.slider1Value']: value,
|
||
['popUpdate.leftSliderPriceWidthX']: leftSliderPriceWidthX + '%'
|
||
})
|
||
} else if (idx === 2) {
|
||
this.setData({
|
||
['popUpdate.slider2Value']: value,
|
||
['popUpdate.rightSliderPriceWidthX']: rightSliderPriceWidthX + '%'
|
||
})
|
||
}
|
||
|
||
popUpdate.value = [popUpdate.slider1Value, popUpdate.slider2Value]
|
||
|
||
this.data.popUpdate = popUpdate
|
||
this.data.newinfo[popUpdate.field] = popUpdate.value
|
||
this.data.fieldinfoNew[popUpdate.field] = popUpdate
|
||
|
||
},
|
||
changed: function (e) {
|
||
let popUpdate = this.data.popUpdate
|
||
if (popUpdate.slider1Value === popUpdate.slider2Value && popUpdate.slider2Value === popUpdate.max) {
|
||
this.setData({
|
||
['popUpdate.change']: true
|
||
})
|
||
}
|
||
},
|
||
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad: function (options) {
|
||
this.calculateOfDate()
|
||
|
||
wx.showLoading({
|
||
title: '加载中',
|
||
})
|
||
|
||
let nowDate = new Date()
|
||
|
||
let that = this;
|
||
this.setData({
|
||
uniqid: options.uniqid || '',
|
||
token: options.token || '',
|
||
types: options.types || 'plus',
|
||
info: this.data.info,
|
||
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() {
|
||
const key = 'MVNBZ-PEFWI-O4OGT-5ADVJ-7QAYJ-NBFY4'; //使用在腾讯位置服务申请的key
|
||
const referer = 'hao'; //调用插件的app的名称
|
||
const location = JSON.stringify({
|
||
latitude: this.data.newinfo.latitude || 22.297759,
|
||
longitude: this.data.newinfo.longitude || 114.179495
|
||
});
|
||
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
|
||
})
|
||
|
||
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"
|
||
})
|
||
})
|
||
},
|
||
|
||
// 新的获取发布数据
|
||
newPublish() {
|
||
wx.showLoading({
|
||
title: '加载中',
|
||
})
|
||
let requestData = {}
|
||
if (this.data.types == 'edit' || this.data.types == 'edit1') {
|
||
requestData = {
|
||
uniqid: this.data.uniqid,
|
||
token: this.options.token,
|
||
intermediary: 6,
|
||
}
|
||
} else {
|
||
requestData = {
|
||
uniqid: this.data.uniqid,
|
||
intermediary: 6,
|
||
}
|
||
}
|
||
|
||
|
||
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 = ""
|
||
let aa = this.data.aa
|
||
let locationObj = {}
|
||
|
||
for (const key in data.fieldinfo) {
|
||
let choices = null
|
||
data.fieldinfo[key].forEach(element => {
|
||
if (!element) return
|
||
|
||
fieldinfoNew[element.field] = {}
|
||
if (aa[element.field]) {
|
||
fieldinfoNew[element.field]['popUpIs'] = aa[element.field].popUpIs
|
||
fieldinfoNew[element.field]['popUpStepState'] = aa[element.field].popUpStepState
|
||
}
|
||
|
||
|
||
if (element.field == "rent" || element.field == "acreage") {
|
||
let estimatedValue = this.data.estimatedValue[element.field]
|
||
|
||
|
||
fieldinfoNew[element.field]['change'] = false
|
||
fieldinfoNew[element.field]['for'] = estimatedValue.for
|
||
fieldinfoNew[element.field]['min'] = estimatedValue.min
|
||
fieldinfoNew[element.field]['step'] = estimatedValue.step
|
||
|
||
// 默认值
|
||
if (Array.isArray(data.info[element.field]) && data.info[element.field].length != 0) {
|
||
let value = data.info[element.field]
|
||
let targetValue = []
|
||
|
||
targetValue = [(value[0] - estimatedValue['min']) / estimatedValue['step'], (value[1] - estimatedValue['min']) / estimatedValue['step']]
|
||
|
||
fieldinfoNew[element.field]['value'] = targetValue
|
||
data.info[element.field] = targetValue
|
||
|
||
} else {
|
||
let targetValue = []
|
||
|
||
targetValue = [estimatedValue.defaultMin, estimatedValue.defaultMax]
|
||
|
||
fieldinfoNew[element.field]['value'] = targetValue
|
||
// data.info[element.field] = targetValue
|
||
}
|
||
|
||
|
||
} else {
|
||
fieldinfoNew[element.field]['value'] = data.info[element.field]
|
||
}
|
||
|
||
|
||
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, i) => {
|
||
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,
|
||
popUpIs: "AListOF",
|
||
popUpStepState: 2,
|
||
choices: []
|
||
}
|
||
} else {
|
||
choicesnew[Math.trunc(el.key) - 1]['choices'].push({
|
||
value: el.value,
|
||
key: el.key,
|
||
field: newfield
|
||
})
|
||
}
|
||
});
|
||
let obj = {
|
||
choices: choicesnew,
|
||
field: element.field,
|
||
title: element.title,
|
||
type: element.type,
|
||
popupwindow: element.popupwindow,
|
||
required: element.required,
|
||
}
|
||
|
||
Object.assign(fieldinfoNew[element.field], obj)
|
||
|
||
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
|
||
}
|
||
})
|
||
}
|
||
let obj = {
|
||
choices: element.choices,
|
||
// 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,
|
||
}
|
||
|
||
Object.assign(fieldinfoNew[element.field], obj)
|
||
|
||
return
|
||
}
|
||
|
||
if (element.field == 'leasetime') {
|
||
let obj = {
|
||
choices: [{
|
||
field: "leasetime",
|
||
value: "随时",
|
||
}, {
|
||
field: "leasetime",
|
||
value: "选择日期",
|
||
// choices: element.choices,
|
||
choices: [1],
|
||
}],
|
||
field: element.field,
|
||
title: element.title,
|
||
type: element.type,
|
||
popupwindow: element.popupwindow,
|
||
required: element.required,
|
||
}
|
||
|
||
Object.assign(fieldinfoNew[element.field], obj)
|
||
return
|
||
}
|
||
|
||
if (element.field == 'property' || element.field == "floor" || element.field == 'sunshinearea') {
|
||
let obj = {}
|
||
let choices = element.choices
|
||
obj[0] = '不限'
|
||
choices.forEach(el => {
|
||
obj[el.key] = el.value
|
||
})
|
||
this.setData({
|
||
[`${element.field}Obj`]: obj
|
||
})
|
||
}
|
||
|
||
if (element.field == 'property' || element.field == 'gender' || element.field == 'intermediary' || element.field == 'elevator' || element.field == 'sunshinearea' || element.field == 'publishergender' || element.field == 'floor') {
|
||
choices = []
|
||
if (element.choices.length >= 0) {
|
||
if ((this.data.types == 'edit' || this.data.types == 'edit1') && element.field != 'floor' && element.field != 'sunshinearea' && element.field != 'property') {
|
||
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
|
||
})
|
||
}
|
||
}
|
||
|
||
let obj = ({
|
||
choices: element.choices,
|
||
field: element.field,
|
||
title: element.title,
|
||
type: element.type,
|
||
popupwindow: element.popupwindow,
|
||
required: element.required,
|
||
})
|
||
Object.assign(fieldinfoNew[element.field], obj)
|
||
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
|
||
// console.log("locationtail", locationtail);
|
||
// 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: []
|
||
}
|
||
locationObj[el.key] = el.value
|
||
} else {
|
||
choicesnew[Math.trunc(el.key) - 1]['choices'].push({
|
||
value: el.value,
|
||
key: el.key,
|
||
field: element.field
|
||
})
|
||
locationObj[el.key] = el.value
|
||
}
|
||
|
||
});
|
||
let obj = {
|
||
choices: choicesnew,
|
||
field: element.field,
|
||
title: element.title,
|
||
type: element.type,
|
||
popupwindow: element.popupwindow,
|
||
required: element.required,
|
||
}
|
||
|
||
Object.assign(fieldinfoNew[element.field], obj)
|
||
return
|
||
}
|
||
|
||
let obj = ({
|
||
// choices,
|
||
field: element.field,
|
||
title: element.title,
|
||
unit: element.unit ? element.unit : null,
|
||
type: element.type,
|
||
placeholder: element.placeholder,
|
||
popupwindow: element.popupwindow,
|
||
required: element.required,
|
||
})
|
||
Object.assign(fieldinfoNew[element.field], obj)
|
||
});
|
||
}
|
||
|
||
|
||
// if (data.type == "edit") this.data.contactInformationState = data.info.iswechattype
|
||
// else data.info.iswechattype = 0
|
||
|
||
if (data.info.wechatdata.aid != 0) this.data.contactInformationState = 2
|
||
// 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,
|
||
fieldinfoNew,
|
||
newcity: data.city,
|
||
newinfo: data.info,
|
||
newToken: data.token,
|
||
imgs: data.info.images,
|
||
allowpublishednum: data.allowpublishednum,
|
||
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,
|
||
locationObj,
|
||
})
|
||
|
||
wx.hideLoading()
|
||
if (this.data.types == 'plus') this.firstStepPopover()
|
||
|
||
}).catch(() => {
|
||
this.setData({
|
||
loding: false
|
||
})
|
||
})
|
||
},
|
||
|
||
// 初始化弹出的窗口
|
||
firstStepPopover() {
|
||
|
||
let field = 'type'
|
||
let step = 0
|
||
let it = 'basic'
|
||
// let field = 'intermediary'
|
||
// let step = 0
|
||
// let it = 'status'
|
||
|
||
let popUpIs = ""
|
||
let popUpStepState = ""
|
||
let popUpdate = {
|
||
...this.data.fieldinfoNew[field]
|
||
}
|
||
popUpIs = popUpdate.popUpIs
|
||
popUpStepState = popUpdate.popUpStepState
|
||
|
||
this.setData({
|
||
step,
|
||
popUpIs,
|
||
popUpdate,
|
||
popUpit: it,
|
||
popUpStepState
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow: function () {
|
||
// 在Mac 是获取 地图插件用户选择的地址信息
|
||
const location = chooseLocation.getLocation()
|
||
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
|
||
})
|
||
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
|
||
})
|
||
},
|
||
// 获取内容
|
||
get_content: function () {
|
||
let that = this;
|
||
let url = '';
|
||
wx.showLoading({
|
||
title: '加载中',
|
||
})
|
||
if (this.data.types == 'edit' || this.data.types == 'edit1') {
|
||
url = app.globalData.config.post.edit;
|
||
} else {
|
||
url = app.globalData.config.post.release
|
||
}
|
||
var sendData = Object.assign({}, this.data.options, {
|
||
session: wx.getStorageSync('session'),
|
||
uniqid: that.data.uniqid,
|
||
token: that.data.token,
|
||
})
|
||
miucms.request(url, sendData).then(data => {
|
||
wx.hideLoading()
|
||
if (data.code != 200) {
|
||
wx.showModal({
|
||
title: '提示',
|
||
content: data.message,
|
||
})
|
||
return false
|
||
}
|
||
for (let i in data.data.info) {
|
||
if (that.data.info[i]) {
|
||
that.data.info[i].value = data.data.info[i]
|
||
}
|
||
if (i == 'currencytext') {
|
||
that.data.info.rent.unit = data.data.info[i];
|
||
}
|
||
}
|
||
var cityid = data.data.city.id;
|
||
|
||
that.data.info.acreage.unit = cityid == '1' ? '平方呎' : '平方米';
|
||
this.data.info.rent.name = (data.data.info.rentalperiod || '月') + '租';
|
||
this.setConfig(data.data.config)
|
||
that.setData({
|
||
// types:data.type || 'plus',
|
||
token: data.data.token,
|
||
uniqid: data.data.uniqid,
|
||
// send_info:data.info,
|
||
url: data.url,
|
||
questions: data.questions || [],
|
||
city: data.data.city,
|
||
info: that.data.info,
|
||
|
||
})
|
||
if (that.data.types == 'edit' || this.data.types == 'edit1') {
|
||
for (let i in data.data.info) {
|
||
if (that.data.info[i]) {
|
||
that.data.info[i]['value'] = data.data.info[i]
|
||
}
|
||
if (i == 'school') this.data.aroundSchoolList = data.data.info.school;
|
||
|
||
|
||
}
|
||
if (data.data.info.images_url && data.data.info.images_url.length > 0) {
|
||
for (let i = 0; i < data.data.info.images.length; i++) {
|
||
that.data.imgs.push({
|
||
aid: data.data.info.images[i],
|
||
url: data.data.info.images_url[i]
|
||
})
|
||
}
|
||
}
|
||
|
||
if (data.data.info.point && data.data.info.point.length == 2) {
|
||
that.data.latitude = data.data.info.point[0];
|
||
that.data.longitude = data.data.info.point[1];
|
||
}
|
||
that.data.city['id'] = data.data.info.cityid
|
||
that.setData({
|
||
info: that.data.info,
|
||
imgs: that.data.imgs,
|
||
timestamp: data.data.info.timestamp,
|
||
updatetime: data.data.info.updatetime,
|
||
latitude: that.data.latitude,
|
||
longitude: that.data.longitude,
|
||
city: that.data.city,
|
||
aroundSchoolList: that.data.aroundSchoolList
|
||
})
|
||
|
||
}
|
||
|
||
}).catch(res => {})
|
||
},
|
||
// 设置选项的值
|
||
setConfig(config) {
|
||
for (let i in config) {
|
||
if (i == 'leaseterm') {
|
||
continue
|
||
}
|
||
if (Array.isArray(this.data.info[i].data)) {
|
||
// 单选,需要传入数组
|
||
this.data.info[i].data = []
|
||
for (let j in config[i]) {
|
||
this.data.info[i].data.push({
|
||
name: config[i][j],
|
||
value: j
|
||
})
|
||
}
|
||
} else {
|
||
// 多选,传入obj
|
||
this.data.info[i].data = Object.assign({}, config[i]);
|
||
}
|
||
}
|
||
},
|
||
|
||
issubmit: false,
|
||
// 提交第二步
|
||
submit2: function (e) {
|
||
let that = this;
|
||
if (this.issubmit) {
|
||
wx.showToast({
|
||
title: '请勿重复提交~',
|
||
icon: 'none'
|
||
})
|
||
return false;
|
||
}
|
||
|
||
this.issubmit = true;
|
||
let images = []
|
||
let status = e.currentTarget.dataset.status;
|
||
wx.showLoading({
|
||
title: '提交中...',
|
||
})
|
||
if (that.data.imgs.length > 0) {
|
||
for (let i = 0; i < that.data.imgs.length; i++) {
|
||
images.push(that.data.imgs[i].aid)
|
||
}
|
||
}
|
||
|
||
let info = {
|
||
images,
|
||
point: []
|
||
}
|
||
if (this.data.latitude) {
|
||
info['point'] = [this.data.latitude, this.data.longitude]
|
||
} else {
|
||
info['point'] = []
|
||
}
|
||
for (let i in this.data.info) {
|
||
info[i] = this.data.info[i].value
|
||
}
|
||
info['school'] = this.data.aroundSchoolList;
|
||
miucms.request(app.globalData.config.post.submit, {
|
||
session: wx.getStorageSync('session'),
|
||
info: info,
|
||
token: that.data.token,
|
||
uniqid: that.data.uniqid,
|
||
type: that.data.types == 'edit1' ? 'plus' : that.data.types,
|
||
status: status,
|
||
|
||
}).then(data => {
|
||
this.issubmit = false;
|
||
wx.hideLoading()
|
||
if (data.extraparam && data.extraparam.mode == 'right') {
|
||
// 提交成功
|
||
|
||
wx.showToast({
|
||
title: data.message,
|
||
})
|
||
|
||
if (status == 0) {
|
||
// 只是保存
|
||
wx.redirectTo({
|
||
url: '/pages/user/user?tab=publish'
|
||
})
|
||
|
||
} else {
|
||
wx.redirectTo({
|
||
url: '/pages/show/show?uniqid=' + data.data.uniqid,
|
||
})
|
||
}
|
||
|
||
} else {
|
||
wx.showModal({
|
||
title: '提示',
|
||
content: data.errMsg || data.message,
|
||
})
|
||
|
||
}
|
||
|
||
}).catch(res => {
|
||
this.issubmit = false
|
||
})
|
||
},
|
||
|
||
// 长内容
|
||
to_textarea: function (e) {
|
||
let {
|
||
title,
|
||
placeholder,
|
||
index
|
||
} = e.currentTarget.dataset;
|
||
if (title == 'village' || title == 'school') {
|
||
let myComponent = this.selectComponent('#inputComponent');
|
||
myComponent.showPage(title);
|
||
return false
|
||
}
|
||
let that = this,
|
||
data = null;
|
||
if (title == 'aroundSchool') {
|
||
data = {
|
||
index,
|
||
distance: that.data.aroundSchoolList[index].distance
|
||
}
|
||
} else {
|
||
data = that.data.info[title].value
|
||
}
|
||
wx.setStorage({
|
||
key: title,
|
||
data: data,
|
||
success: function (res) {
|
||
that.setData({
|
||
write_long_textarea: title
|
||
})
|
||
wx.navigateTo({
|
||
url: '../textarea/textarea?name=' + title + '&placeholder=' + placeholder,
|
||
})
|
||
}
|
||
})
|
||
|
||
},
|
||
|
||
wxParseTagATap: function (e) {
|
||
var url = e.currentTarget.dataset.src;
|
||
wx.navigateTo({
|
||
url: url,
|
||
})
|
||
},
|
||
// 有二级选项的提交
|
||
submitMore(e) {
|
||
this.data.info[e.currentTarget.dataset.name].value = e.detail.data;
|
||
|
||
this.setData({
|
||
info: this.data.info
|
||
})
|
||
},
|
||
// 有一级选项的提交
|
||
submitSingle(e) {
|
||
this.data.info[e.currentTarget.dataset.name].value = e.detail.value;
|
||
|
||
this.setData({
|
||
info: this.data.info
|
||
})
|
||
},
|
||
// 改变日期
|
||
changeDate(e) {
|
||
this.data.info.leasetime.value = e.detail.value.substring(0, 10);
|
||
this.setData({
|
||
info: this.data.info
|
||
})
|
||
},
|
||
changeInputSelect() {},
|
||
// 点击获取位置
|
||
get_location: function () {
|
||
let that = this;
|
||
wx.getLocation({
|
||
success: function (resget) {
|
||
wx.chooseLocation({
|
||
enableHighAccuracy: true,
|
||
latitude: that.data.latitude || '22.297759',
|
||
longitude: that.data.longitude || '114.179495',
|
||
success: function (res) {
|
||
that.data.info.address.value = res.address;
|
||
that.setData({
|
||
info: that.data.info,
|
||
latitude: res.latitude,
|
||
longitude: res.longitude
|
||
})
|
||
if (res.address) {
|
||
// 如果能获取到address
|
||
return false
|
||
}
|
||
},
|
||
fail(err) {
|
||
console.log(err);
|
||
}
|
||
})
|
||
},
|
||
fail(res) {
|
||
that.setData({
|
||
isrefusedAuthLocation: 1
|
||
})
|
||
}
|
||
})
|
||
},
|
||
bindopensetting(res) {
|
||
var status = res.detail.authSetting['scope.userLocation'],
|
||
that = this;
|
||
|
||
if (status) {
|
||
//用户同意授权
|
||
that.get_location()
|
||
that.setData({
|
||
isrefusedAuthLocation: 0
|
||
})
|
||
|
||
} else {
|
||
that.setData({
|
||
isrefusedAuthLocation: 2
|
||
})
|
||
wx.showToast({
|
||
title: '您已拒绝授权地址,请点击自行填写~',
|
||
icon: 'none'
|
||
})
|
||
|
||
}
|
||
},
|
||
clearleasetime() {
|
||
this.data.info.leasetime.value = 0;
|
||
|
||
this.setData({
|
||
info: this.data.info
|
||
})
|
||
},
|
||
submitSchool(e) {
|
||
this.setData({
|
||
aroundSchoolList: [...e.detail]
|
||
})
|
||
},
|
||
|
||
// 切换发布须知的状态
|
||
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[0]
|
||
let popUpdate = this.data.popUpdate
|
||
this.setData({
|
||
leaseTimeValue: val,
|
||
['newinfo.rentalduration']: popUpdate.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;
|
||
// 实际月份比curMonth大1,下面将月份设置为下一个月
|
||
curDate.setMonth(curMonth);
|
||
// 将日期设置为0,表示自动计算为上个月(这里指的是当前月份)的最后一天
|
||
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
|
||
this.popUpNextStep()
|
||
},
|
||
|
||
// 点击操作弹出弹窗
|
||
clickOption(e) {
|
||
let {
|
||
field,
|
||
step,
|
||
it
|
||
} = e.currentTarget.dataset
|
||
|
||
let popUpIs = ""
|
||
let popUpStepState = ""
|
||
let fieldinfoNew = this.data.fieldinfoNew
|
||
if (this.data.fieldinfo[it][step].popupwindow == 0) return
|
||
|
||
popUpIs = fieldinfoNew[field].popUpIs
|
||
popUpStepState = fieldinfoNew[field].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
|
||
|
||
if ((field == "acreage" || field == "rent") && this.data.newinfo[field].length < 2) {
|
||
let estimatedValue = this.data.estimatedValue
|
||
this.data.newinfo[field] = [estimatedValue[field].defaultMin, estimatedValue[field].defaultMax]
|
||
this.data.fieldinfoNew[field]['value'] = [estimatedValue[field].defaultMin, estimatedValue[field].defaultMax]
|
||
this.data.fieldinfoNew[field]['slider1Value'] = estimatedValue[field].defaultMin
|
||
this.data.fieldinfoNew[field]['slider2Value'] = estimatedValue[field].defaultMax
|
||
} else if ((field == "floor" || field == "property" || field == 'sunshinearea') && this.data.newinfo[field].length == 0) {
|
||
this.data.newinfo[field] = [0]
|
||
this.data.fieldinfoNew[field]['value'] = [0]
|
||
} else this.data.fieldinfoNew[field]['value'] = this.data.newinfo[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
|
||
|
||
let popUpSubtitle1 = this.data.popUpSubtitle
|
||
let popUpIs = ""
|
||
let popUpTitle = ""
|
||
let popUpStepState = ""
|
||
let popUpSubtitle = ""
|
||
if (choices) {
|
||
popUpSubtitle = value
|
||
console.log("popUpSubtitle0", popUpSubtitle);
|
||
popUpIs = this.data.popUpIs
|
||
|
||
let popUpStepState = this.data.popUpStepState
|
||
if (field == "rentalduration") {
|
||
popUpIs = "leaseTime"
|
||
popUpStepState = 2
|
||
}
|
||
|
||
if (field == "leasetime") {
|
||
popUpIs = "ofDate"
|
||
popUpStepState = 1
|
||
}
|
||
|
||
this.setData({
|
||
['popUpdate.choices']: choices,
|
||
['popUpdate.value']: value,
|
||
popUpSubtitle,
|
||
popUpIs,
|
||
popUpStepState,
|
||
})
|
||
|
||
return
|
||
|
||
} else {
|
||
// 选择出租方式后需要 >> 显示
|
||
if (this.data.fieldinfo[this.data.popUpit][this.data.step].field == 'type') {
|
||
let headValue = this.data.popUpdate.value
|
||
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}`]: headValue + '>>' + 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 (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
|
||
}
|
||
|
||
let fieldinfoNew = this.data.fieldinfoNew
|
||
let popUpdate = {
|
||
...fieldinfoNew[this.data.fieldinfo[this.data.popUpit][this.data.step].field]
|
||
}
|
||
let field = popUpdate.field
|
||
if (this.data.newinfo[field] != null && this.data.newinfo[field] != "") {
|
||
this.setData({
|
||
popUpIs: "",
|
||
popUpSubtitle
|
||
})
|
||
return
|
||
}
|
||
this.optionScroll(field)
|
||
popUpIs = popUpdate.popUpIs
|
||
popUpTitle = popUpdate.title
|
||
popUpStepState = popUpdate.popUpStepState
|
||
if (popUpIs == 'unilineInput' || popUpIs == 'multilineInput' || popUpIs == 'multilineInput1') this.data.focustitle = popUpdate.field
|
||
|
||
if (popUpdate.field == "sunshinearea" && this.data.newinfo['sunshinearea'].length == 0) {
|
||
this.data.newinfo['sunshinearea'] = [0]
|
||
this.setData({
|
||
['newinfo.sunshinearea']: [0]
|
||
})
|
||
popUpdate.value = [0]
|
||
}
|
||
|
||
|
||
this.setData({
|
||
popUpdate,
|
||
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()
|
||
}
|
||
|
||
if (popUpIs == "rent-budget") {
|
||
let popUpdate = this.data.popUpdate
|
||
this.setData({
|
||
[`newinfo.${popUpdate.field}`]: popUpdate['value']
|
||
})
|
||
|
||
console.log("newinfo", this.data.newinfo);
|
||
|
||
}
|
||
|
||
// console.log("1popUpIs0", this.data.popUpdate);
|
||
|
||
this.setData({
|
||
popUpSubtitle,
|
||
popUpTitle,
|
||
popUpIs,
|
||
popUpStepState
|
||
})
|
||
},
|
||
|
||
// 选择弹窗选项多选
|
||
selectMultipleOption(e) {
|
||
let {
|
||
key,
|
||
value
|
||
} = e.currentTarget.dataset
|
||
|
||
let popUpdate = this.data.popUpdate
|
||
let targetValue = popUpdate.value ? [...popUpdate.value] : []
|
||
key = key.toString()
|
||
if (key == 0) targetValue = [0]
|
||
else {
|
||
if (targetValue.includes(0)) targetValue.splice(targetValue.indexOf(0), 1)
|
||
if (targetValue.includes("0")) targetValue.splice(targetValue.indexOf("0"), 1)
|
||
if (targetValue.includes(key)) targetValue.splice(targetValue.indexOf(key), 1)
|
||
else targetValue.push(key)
|
||
}
|
||
|
||
if (popUpdate.field == "location" && targetValue.length > 6) return
|
||
|
||
targetValue.sort()
|
||
|
||
if (targetValue.length == 0) targetValue = [0]
|
||
|
||
this.data.newinfo[popUpdate.field] = targetValue
|
||
|
||
this.setData({
|
||
['popUpdate.value']: targetValue,
|
||
newinfo: this.data.newinfo
|
||
})
|
||
|
||
},
|
||
|
||
// 弹出上角的关闭弹窗
|
||
closePopUp() {
|
||
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 = ""
|
||
|
||
|
||
let popUpdate = this.data.popUpdate
|
||
let leaseTimeValue = this.data.leaseTimeValue
|
||
if (this.data.popUpIs == 'leaseTime' && currentField == 'rentalduration') {
|
||
this.setData({
|
||
['newinfo.rentalduration']: popUpdate.choices[leaseTimeValue].value
|
||
})
|
||
}
|
||
|
||
this.setData({
|
||
popUpIs: "",
|
||
popUpit: "",
|
||
popUpSubtitle: "",
|
||
newinfo: this.data.newinfo
|
||
})
|
||
},
|
||
|
||
// 填好了
|
||
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 fieldinfoNew = this.data.fieldinfoNew
|
||
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: ""
|
||
})
|
||
return
|
||
}
|
||
|
||
let popUpdate = fieldinfoNew[this.data.fieldinfo[this.data.popUpit][this.data.step].field]
|
||
if (popUpdate.popUpIs == 'nearSchool') {
|
||
this.data.nearSchoolList.push({
|
||
name: '',
|
||
distance: ""
|
||
})
|
||
this.setData({
|
||
nearSchoolList: this.data.nearSchoolList
|
||
})
|
||
}
|
||
this.optionScroll(popUpdate.field)
|
||
this.setData({
|
||
popUpIs: popUpdate.popUpIs,
|
||
popUpTitle: popUpdate.title,
|
||
popUpdate,
|
||
popUpStepState: popUpdate.popUpStepState
|
||
})
|
||
},
|
||
|
||
// 下一步
|
||
popUpNextStep(e) {
|
||
let currentField = this.data.popUpdate.field
|
||
let popUpIs = ""
|
||
|
||
// 下一步是附近学校时 判断学校名是否为空 空则删除对应学校数据
|
||
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.popUpdate.choices[this.data.leaseTimeValue].value
|
||
})
|
||
}
|
||
|
||
if (currentField == 'rent') {
|
||
let value = this.data.popUpdate.value || []
|
||
let fieldinfoNew1 = this.data.fieldinfoNew.rent
|
||
if (value.length == 0) value = [fieldinfoNew1.slider1Value, fieldinfoNew1.slider2Value]
|
||
|
||
this.setData({
|
||
['newinfo.rent']: value
|
||
})
|
||
}
|
||
|
||
// 判断当前弹窗是否是必填项 再判断是否有填写数据,有执行下一步
|
||
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: ""
|
||
})
|
||
return
|
||
}
|
||
|
||
let field = this.data.fieldinfo[this.data.popUpit][this.data.step].field
|
||
let popUpdate = {
|
||
...this.data.fieldinfoNew[field]
|
||
}
|
||
|
||
let popUpStepState = popUpdate.popUpStepState
|
||
|
||
|
||
// 因为 field == 'address' 分香港和非香港地区 这个是香港地区的 地址,调用地图API
|
||
if (this.data.fieldinfoNew[popUpdate.field].field == 'address') {
|
||
if (this.data.fieldinfoNew.address.type == 'map') popUpIs = "AddressHongKong"
|
||
}
|
||
|
||
if (this.data.types.indexOf('edit') > -1 && popUpdate.popupwindow == 0) {
|
||
this.setData({
|
||
popUpIs: ""
|
||
})
|
||
return
|
||
}
|
||
|
||
this.optionScroll(this.data.fieldinfoNew[popUpdate.field].field)
|
||
if (popUpdate.popUpIs == 'unilineInput' || popUpdate.popUpIs == 'multilineInput' || popUpdate.popUpIs == 'multilineInput1') {
|
||
this.data.focustitle = popUpdate.field
|
||
}
|
||
|
||
|
||
if ((field == "acreage" || field == 'rent') && this.data.newinfo[field].length < 2) {
|
||
// let estimatedValue = this.data.estimatedValue[field]
|
||
// this.data.newinfo[field] = [estimatedValue.defaultMin, estimatedValue.defaultMax]
|
||
// popUpdate['value'] = [estimatedValue.defaultMin, estimatedValue.defaultMax]
|
||
this.setData({
|
||
[`newinfo.${field}`]: popUpdate['value']
|
||
})
|
||
|
||
} else if ((field == "floor" || field == "property" || field == 'sunshinearea') && this.data.newinfo[field].length == 0) {
|
||
this.setData({
|
||
[`newinfo.${field}`]: [0]
|
||
})
|
||
popUpdate['value'] = [0]
|
||
} else popUpdate['value'] = this.data.newinfo[field]
|
||
|
||
this.setData({
|
||
popUpdate,
|
||
popUpIs: popUpdate.popUpIs,
|
||
popUpStepState: popUpdate.popUpStepState,
|
||
popUpTitle: popUpdate.title,
|
||
popUpSubtitle: "",
|
||
nearSchoolList: this.data.nearSchoolList,
|
||
focustitle: this.data.focustitle
|
||
})
|
||
},
|
||
|
||
// 单行输入框的输入
|
||
popUpInput(e) {
|
||
let value = e.detail.value
|
||
let {
|
||
field,
|
||
popupit
|
||
} = e.currentTarget.dataset
|
||
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
|
||
let {
|
||
field,
|
||
popupit
|
||
} = e.currentTarget.dataset
|
||
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 (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
|
||
|
||
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['tel'] && !newinfo['whatsapp'] && !newinfo['wechatdata']['aid'] && status == 1) {
|
||
this.issubmit = false
|
||
wx.hideLoading()
|
||
wx.showModal({
|
||
title: '提示',
|
||
content: '请填写联系方式'
|
||
})
|
||
|
||
this.calculateTargetPopup('wechat')
|
||
return
|
||
}
|
||
|
||
if (!newinfo['wechatdata']['aid']) newinfo.iswechattype = 0
|
||
|
||
|
||
|
||
if (newinfo.leasetime == '随时') newinfo.leasetime = 0
|
||
|
||
for (const key in fieldinfo) {
|
||
fieldinfo[key].forEach(element => {
|
||
if (!element) return
|
||
if ((element.field == "rent" || element.field == 'acreage') && newinfo[element.field] && newinfo[element.field].length != 0) {
|
||
|
||
let estimatedValue = this.data.estimatedValue[element.field]
|
||
let value = newinfo[element.field]
|
||
value = value.sort(function (a, b) {
|
||
return a - b;
|
||
})
|
||
value = [(value[0] * estimatedValue['step'] + estimatedValue['min']), value[1] * estimatedValue['step'] + estimatedValue['min']]
|
||
newinfo[element.field] = value
|
||
}
|
||
// 出租方式
|
||
if (element.field == "type") {
|
||
let fieldinfoNew = this.data.fieldinfoNew
|
||
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 == "gender") {
|
||
element.choices.forEach((el, index) => {
|
||
if (el.value == newinfo.gender) {
|
||
newinfo.gender = index + 1
|
||
}
|
||
})
|
||
}
|
||
|
||
// 电梯 晾晒区
|
||
if (element.field == "elevator" || element.field == 'publishergender' || element.field == 'intermediary') {
|
||
element.choices.forEach(res => {
|
||
if (res.value == newinfo[element.field]) {
|
||
newinfo[element.field] = res.key
|
||
}
|
||
})
|
||
}
|
||
})
|
||
}
|
||
|
||
// miucms.request(app.globalData.baseURL + '/tenement/publish/submit', {
|
||
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 {
|
||
this.setData({
|
||
popUpIs: "succeed-pop"
|
||
})
|
||
setTimeout(() => {
|
||
wx.redirectTo({
|
||
// url: '/pages/show/show?uniqid=' + res.data.uniqid + '&cityid=' + this.data.newcity.id,
|
||
url: '/pages/show/show?uniqid=' + res.data.uniqid
|
||
})
|
||
}, 2000)
|
||
|
||
}
|
||
}
|
||
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 {
|
||
wx.chooseLocation({
|
||
latitude: this.data.newinfo.latitude || 22.297759,
|
||
longitude: this.data.newinfo.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
|
||
})
|
||
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/publish/uploadweixinqrcode`,
|
||
url: `${app.globalData.baseURL}/tenement/v2/api/publish/uploadweixinqrcode`,
|
||
filePath: imgUrl,
|
||
name: 'files',
|
||
header: app.globalData.header,
|
||
success: function (res) {
|
||
if (res.statusCode == 500) {
|
||
wx.hideLoading()
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: '上传失败!',
|
||
})
|
||
}
|
||
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
|
||
|
||
let popUpdate = this.data.fieldinfoNew[field]
|
||
|
||
if (field == "rent" && this.data.newinfo[field].length < 2) {
|
||
// this.data.newinfo[field] = [estimatedValue[field].defaultMin, estimatedValue[field].defaultMax]
|
||
// popUpdate['value'] = [estimatedValue[field].defaultMin, estimatedValue[field].defaultMax]
|
||
// popUpdate['slider1Value'] = estimatedValue[field].defaultMin
|
||
// popUpdate['slider2Value'] = estimatedValue[field].defaultMax
|
||
|
||
this.setData({
|
||
[`nnewinfo${field}`]: popUpdate['value']
|
||
})
|
||
|
||
}
|
||
|
||
if ((field == "floor" || field == "property" || field == 'sunshinearea') && this.data.newinfo[field].length == 0) {
|
||
this.data.newinfo[field] = [0]
|
||
this.data.fieldinfoNew[field]['value'] = [0]
|
||
this.setData({
|
||
newinfo: this.data.newinfo,
|
||
fieldinfoNew: this.data.fieldinfoNew
|
||
})
|
||
}
|
||
|
||
for (const key in fieldinfo) {
|
||
fieldinfo[key].forEach((element, index) => {
|
||
if (element.field == field) {
|
||
this.setData({
|
||
popUpIs: popUpdate.popUpIs,
|
||
popUpTitle: popUpdate.title,
|
||
popUpdate,
|
||
step: index,
|
||
popUpit: key,
|
||
popUpStepState: popUpdate.popUpStepState
|
||
})
|
||
}
|
||
})
|
||
|
||
}
|
||
|
||
// for (const key in fieldinfo) {
|
||
// console.log("fieldinfo", fieldinfo);
|
||
|
||
// fieldinfo[key].forEach((element, index) => {
|
||
// if (element.field == field) {
|
||
// this.data.aa.forEach(el => {
|
||
// if (el.name == element.title) {
|
||
// 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
|
||
|
||
if (!field) return
|
||
wx.pageScrollTo({
|
||
selector: `.clickInput${field}`,
|
||
offsetTop: -200
|
||
})
|
||
|
||
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
|
||
},
|
||
|
||
// 单独处理目标区域的删除
|
||
deleteLocation(e) {
|
||
let key = e.currentTarget.dataset.key
|
||
let location = this.data.newinfo.location
|
||
let value = this.data.popUpdate.value
|
||
|
||
location.splice(location.indexOf(key), 1)
|
||
|
||
this.setData({
|
||
['newinfo.location']: location,
|
||
['popUpdate.value']: location,
|
||
})
|
||
|
||
},
|
||
|
||
// 房租预算和面积的 公共方法
|
||
bindChangeRent(e) {
|
||
let value = e.detail.value
|
||
console.log(value, this.data.popUpdate);
|
||
let popUpdate = this.data.popUpdate
|
||
this.setData({
|
||
[`newinfo.${popUpdate.field}`]: value,
|
||
[`popUpdate.value`]: value
|
||
})
|
||
},
|
||
|
||
|
||
}) |