// 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: { 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 }, intermediary: { name: '发布者身份', value: '', data: [], title: "intermediary", need: 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, // 步数 在当前模块的 的步数 有basic模块等 看 popUpOrder 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" }], 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, }, /** * 生命周期函数--监听页面加载 */ 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) } }, // 新的获取发布数据 newPublish() { wx.showLoading({ title: '加载中', }) let requestData = {} if (this.data.types == 'edit' || this.data.types == 'edit1') { requestData = { uniqid: this.data.uniqid, token: this.options.token } } else { requestData = { uniqid: this.data.uniqid, } } miucms.request(`${app.globalData.baseURL}/tenement/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 = "" console.log("fieldinfo", data.fieldinfo); 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: [] } } 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 == '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') { 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({ fieldinfo: data.fieldinfo, fieldinfoNew, newcity: data.city, newinfo: data.info, newToken: data.token, newType: data.type, 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, }) wx.hideLoading() if (this.data.types == 'plus') { this.firstStepPopover() } }).catch(() => { this.setData({ loding: false }) }) }, firstStepPopover() { // let field = 'type' let field = 'intermediary' let step = 0 let it = 'status' let popUpIs = "" let popUpStepState = "" this.data.aa.forEach(element => { // if (this.data.fieldinfo['basic'][0].title == element.name) { if (this.data.fieldinfo['status'][0].title == element.name) { popUpIs = element.popUpIs popUpStepState = element.popUpStepState } }); console.log("fieldinfoNew", this.data.fieldinfoNew); this.setData({ step, popUpIs, popUpdate: this.data.fieldinfoNew[field], popUpit: it, // popUpit: "status", 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.video_url && data.data.info.video_url.length > 0) { for (let i = 0; i < data.data.info.video.length; i++) { that.data.videos.push({ aid: data.data.info.video[i], url: data.data.info.video_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, videos: that.data.videos, 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 = [], video = []; 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) } } if (that.data.videos.length > 0) { for (let i = 0; i < that.data.videos.length; i++) { video.push(that.data.videos[i].aid) } } let info = { images, video, 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 }) }, // 选择图片 get_img: function () { var that = this; let limitSuffix = ['svg'] // 需要限制的后缀数组 wx.chooseImage({ count: 6 - that.data.imgs.length, sizeType: ['compressed'], success: function (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 < 10 && !limitSuffix.includes(suffix.toLowerCase())) { // 小于3M且照片数量<6的时候才触发上传 that.upload_picnew(res.tempFiles[i].path, "image") } else if (size >= 10) { isLt10M = false; } else if (limitSuffix.includes(suffix.toLowerCase())) { isSvg = false } } if (!isLt10M) { // 存在大于3M的,只提示一次 wx.showModal({ title: '提示', content: '图片大小不能超过10M', }) } else if (!isSvg) { wx.showModal({ title: '提示', content: '上传文件后缀不允许', }) } }, fail(err) { wx.showModal({ title: 'chooseImageErr', content: err, }) } }) }, upload_picnew: function (imgUrl, type) { var that = this; const uploadTask = wx.uploadFile({ url: `${app.globalData.baseURL}/tenement/publish/upload`, filePath: imgUrl, name: 'files', formData: { uniqid: that.data.uniqid, session: app.globalData.session, type }, 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 if (that.data.imgs.length < 6) { that.data.imgs.push({ url: data.url, aid: data.aid }) that.setData({ imgs: that.data.imgs }) } else { wx.showToast({ title: '最多可上传6张', icon: 'none' }) } } 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, }) } }) }, // 上传图片 upload_pic: function (imgUrl) { var that = this; const uploadTask = wx.uploadFile({ url: 'https://app.gter.net/upload', filePath: imgUrl, name: 'files', formData: { uniqid: that.data.uniqid, session: app.globalData.session }, header: app.globalData.header, success: function (res) { try { var data = app.return_data(res); if (data.aid > 0) { // 长度<6个的时候再push if (that.data.imgs.length < 6) { that.data.imgs.push({ url: data.url, aid: data.aid }) that.setData({ imgs: that.data.imgs }) } else { wx.showToast({ title: '最多可上传6张', icon: 'none' }) } } else { wx.showToast({ title: data.state, icon: 'none' }) } } catch (e) { wx.showToast({ title: 'uploadCatch' + e, icon: 'none' }) } }, fail: function (err) { wx.showModal({ title: 'uploadFileErr', content: err, }) } }) }, // 选择mp4 get_video: function () { let that = this; wx.chooseVideo({ count: 1, success: function (res) { var size = res.size / 1024 / 1024; if (size > 10) { wx.showModal({ title: '提示', content: '视频大小不能超过10M', }) } else { that.upload_videonew(res.tempFilePath) } } }) }, // 上传mp4 upload_video: function (videoUrl) { var that = this; wx.showLoading({ title: '视频上传中', }) const uploadTask = wx.uploadFile({ url: 'https://app.gter.net/upload', filePath: videoUrl, name: 'files', formData: { uniqid: that.data.uniqid, session: app.globalData.session, type: 'video' }, header: app.globalData.header, success: function (res) { try { var data = app.return_data(res); that.data.videos.push({ url: data.url, aid: data.aid }) that.setData({ videos: that.data.videos }) } catch (e) { wx.showToast({ title: 'uploadVideoCatch' + e, icon: 'none' }) } }, fail: function (err) { wx.showModal({ title: 'uploadVideoErr', content: err, }) }, complete(res) { wx.hideLoading() } }) }, upload_videonew: function (videoUrl) { var that = this; wx.showLoading({ title: '视频上传中', }) const uploadTask = wx.uploadFile({ url: `${app.globalData.baseURL}/tenement/publish/upload`, filePath: videoUrl, name: 'files', formData: { uniqid: that.data.uniqid, session: app.globalData.session, type: 'video' }, 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') { this.data.imgs.splice(index, 1) this.setData({ imgs: this.data.imgs }) } else { this.setData({ videos: [] }) } }, // 长内容 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 }) }, // 点击规则3中的图片预览 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() console.log("time", time); 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 let that = this that.popUpNextStep() }, // 点击操作弹出弹窗 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].title == element.name) { 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 } 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 }) } } this.data.aa.forEach(element => { if (value == element.name) { console.log("element.name", element.name); popUpStepState = element.popUpStepState popUpIs = element.popUpIs popUpTitle = this.data.fieldinfo[element.it][this.data.step].title } }); 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 } console.log(this.data.popUpit, "popUpit"); this.data.aa.forEach(element => { if (this.data.fieldinfo[this.data.popUpit][this.data.step].title == element.name) { 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() { 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 }) }, // 填好了 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: "" }) return } this.data.aa.forEach(element => { if (this.data.fieldinfo[this.data.popUpit][this.data.step].title == element.name) { 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 }) } }); }, // 下一步 popUpNextStep(e) { let currentField = this.data.fieldinfo[this.data.popUpit][this.data.step].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.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: "" }) return } this.data.aa.forEach(element => { if (this.data.fieldinfo[this.data.popUpit][this.data.step].title == element.name) { // 附近学校没有数据时加一个默认数据 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 }) } }); }, // 单行输入框的输入 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 (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 == "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 } }) }) } }) } miucms.request(app.globalData.baseURL + '/tenement/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 { wx.redirectTo({ url: '/pages/show/show?uniqid=' + res.data.uniqid + '&cityid=' + this.data.newcity.id, }) } } 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 => { console.log(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`, filePath: imgUrl, name: 'files', 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.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.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 } 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 }) }, // 禁止用户滚动,原因是有可能输入框会被用户滚走 handScroll() { return } })