调整
This commit is contained in:
+239
-206
@@ -14,6 +14,14 @@
|
||||
<u-icon name="arrow-down" color="#fff" size="20"></u-icon>
|
||||
</view>
|
||||
</picker>
|
||||
<view class="mag-top">
|
||||
<view class="section-label">型号</view>
|
||||
<MultiSelectSearch
|
||||
v-model="form.model"
|
||||
:options="modelOptions"
|
||||
placeholder="请输入型号,支持搜索和直接输入"
|
||||
/>
|
||||
</view>
|
||||
<view class="mag-top">
|
||||
<textarea v-model="form.content" class="content-textarea" placeholder="请输入文字内容"
|
||||
:maxlength="maxWords" @input="handleContentInput" />
|
||||
@@ -45,6 +53,10 @@
|
||||
<u-icon name="info-circle" size="18" color="#A6ABB7"></u-icon>
|
||||
<text>文字不多于2000字,图片不多于9张</text>
|
||||
</view>
|
||||
<view class="mag-top">
|
||||
<view class="section-label">小区名称(选填)</view>
|
||||
<input type="text" v-model="form.location_name" placeholder="请输入小区名称" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="agreement">
|
||||
@@ -95,229 +107,250 @@
|
||||
|
||||
<script>
|
||||
import { request,showToast } from '@/api/apiT.js'
|
||||
export default {
|
||||
name: 'PublishPage',
|
||||
data(){
|
||||
return {
|
||||
categoryOptions:[],
|
||||
form:{
|
||||
category:'',
|
||||
category_id:'',
|
||||
content:'',
|
||||
media:[]
|
||||
import MultiSelectSearch from '@/components/MultiSelectSearch.vue'
|
||||
export default {
|
||||
components: {
|
||||
MultiSelectSearch
|
||||
},
|
||||
name: 'PublishPage',
|
||||
data(){
|
||||
return {
|
||||
categoryOptions:[],
|
||||
modelOptions:[], // 型号选项列表
|
||||
form:{
|
||||
category:'',
|
||||
category_id:'',
|
||||
model:[], // 改为数组支持多选
|
||||
content:'',
|
||||
location_name:'',
|
||||
media:[]
|
||||
},
|
||||
selfChecked: false,
|
||||
showlogin:false,
|
||||
viewAgreementcont:'',
|
||||
iconurl:'',
|
||||
maxWords:2000,
|
||||
maxMedia:9,
|
||||
agree:false,
|
||||
show:false,
|
||||
}
|
||||
},
|
||||
computed:{
|
||||
canSubmit(){
|
||||
return this.agree && this.form.content.trim().length>0 && this.form.media.length>0
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getcategory()
|
||||
this.getModelOptions()
|
||||
},
|
||||
onShow() {
|
||||
|
||||
this.syncTabbar()
|
||||
},
|
||||
methods:{
|
||||
goprivacy(){
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/agreement',// 替换为你要跳转的页面路径
|
||||
});
|
||||
},
|
||||
selfChecked: false,
|
||||
showlogin:false,
|
||||
viewAgreementcont:'',
|
||||
iconurl:'',
|
||||
maxWords:2000,
|
||||
maxMedia:9,
|
||||
agree:false,
|
||||
show:false,
|
||||
}
|
||||
},
|
||||
computed:{
|
||||
canSubmit(){
|
||||
return this.agree && this.form.content.trim().length>0 && this.form.media.length>0
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getcategory()
|
||||
},
|
||||
onShow() {
|
||||
|
||||
this.syncTabbar()
|
||||
},
|
||||
methods:{
|
||||
goprivacy(){
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/agreement',// 替换为你要跳转的页面路径
|
||||
});
|
||||
},
|
||||
gouser(){
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/agreementuser',// 替换为你要跳转的页面路径
|
||||
});
|
||||
},
|
||||
selfChangde(e) {
|
||||
this.selfChecked = !this.selfChecked;
|
||||
},
|
||||
loginbtn(){
|
||||
if(!this.selfChecked){
|
||||
uni.showToast({
|
||||
title:this.$t('home.arginimg'),
|
||||
icon: 'none'
|
||||
gouser(){
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/agreementuser',// 替换为你要跳转的页面路径
|
||||
});
|
||||
return false
|
||||
}
|
||||
},
|
||||
getPhoneNumber(e) {
|
||||
let that = this;
|
||||
request({
|
||||
url:'miniapp/phone',
|
||||
method:'POST',
|
||||
data:{
|
||||
phone_code: e.detail.code,
|
||||
}
|
||||
}).then(res => {
|
||||
if (res.data.code == -1) {
|
||||
},
|
||||
selfChangde(e) {
|
||||
this.selfChecked = !this.selfChecked;
|
||||
},
|
||||
loginbtn(){
|
||||
if(!this.selfChecked){
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
title:this.$t('home.arginimg'),
|
||||
icon: 'none'
|
||||
});
|
||||
|
||||
} else if (res.data.code == 200) {
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'none'
|
||||
});
|
||||
//返回数据接收成功
|
||||
uni.setStorageSync('is_login', true);
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
getcategory(){
|
||||
request({
|
||||
url:'common/post/category/list',
|
||||
method:'GET'
|
||||
}).then(res => {
|
||||
if (res.data.code == 200) {
|
||||
this.categoryOptions = res.data.data.records || [];
|
||||
this.form.category = res.data.data.records[0].name
|
||||
this.form.category_id = res.data.data.records[0].id
|
||||
this.iconurl = res.data.data.records[0].icon_preset_pull
|
||||
}
|
||||
})
|
||||
},
|
||||
syncTabbar(){
|
||||
uni.setTabBarItem({ index:0, text:this.$t('tabbar.home') })
|
||||
uni.setTabBarItem({ index:1, text:this.$t('tabbar.square') })
|
||||
uni.setTabBarItem({ index:2, text:this.$t('tabbar.publish') })
|
||||
uni.setTabBarItem({ index:3, text:this.$t('tabbar.mine') })
|
||||
},
|
||||
goBack(){
|
||||
uni.navigateBack()
|
||||
},
|
||||
onCategoryChange(e){
|
||||
console.log(e)
|
||||
const index = e.detail.value; // picker 返回的 index
|
||||
const selectCity = this.categoryOptions[index]; // 直接取整条数据
|
||||
this.iconurl = selectCity.icon_preset_pull
|
||||
this.form.category = selectCity.name
|
||||
this.form.category_id = selectCity.id
|
||||
},
|
||||
handleContentInput(e){
|
||||
if(e.detail.value.length>this.maxWords){
|
||||
this.form.content = e.detail.value.slice(0,this.maxWords)
|
||||
}
|
||||
},
|
||||
uploadfn(imgUrl){
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: 'https://bsh.info.hb.hnzhwlkj.cn/upload/image?scene=postlist',
|
||||
filePath: imgUrl,
|
||||
name: 'image',
|
||||
header:{'content-type': 'application/x-www-form-urlencoded','Fdesk-Auth-Token': 'Bearer ' + uni.getStorageSync('token'),'Fdesk-Language': uni.getStorageSync('i18locale')?uni.getStorageSync('i18locale'):'zh','Fdesk-Login-Type': 'wechat','Fdesk-System-Code':'wechat'},
|
||||
success: (uploadFileRes) => {
|
||||
const res = JSON.parse(uploadFileRes.data || '{}')
|
||||
if(res && res.data && res.data.href){
|
||||
resolve(res.data.href)
|
||||
}else{
|
||||
reject('上传失败')
|
||||
}
|
||||
},
|
||||
fail: (err) => reject(err)
|
||||
});
|
||||
})
|
||||
},
|
||||
selectMedia(e){
|
||||
const allowCount = this.maxMedia - this.form.media.length
|
||||
if(allowCount <= 0){
|
||||
uni.showToast({
|
||||
title:`最多只能上传${this.maxMedia}张图片`,
|
||||
icon:'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
const tempFilePaths = e.tempFilePaths || (e.tempFiles || []).map(item => item.path || item.url)
|
||||
const paths = tempFilePaths.slice(0, allowCount)
|
||||
if(paths.length === 0){
|
||||
return
|
||||
}
|
||||
Promise.all(paths.map(p => this.uploadfn(p))).then(urls => {
|
||||
urls.forEach(url => {
|
||||
this.form.media.push(url)
|
||||
})
|
||||
}).catch(() => {
|
||||
uni.showToast({
|
||||
title:'图片上传失败,请重试',
|
||||
icon:'none'
|
||||
})
|
||||
})
|
||||
},
|
||||
delfn(e){
|
||||
this.form.media.splice(e.index, 1)
|
||||
},
|
||||
deleteMedia(index){
|
||||
this.form.media.splice(index, 1)
|
||||
},
|
||||
toggleAgreement(){
|
||||
this.agree = !this.agree
|
||||
},
|
||||
viewAgreement(){
|
||||
request({
|
||||
url:'common/agreement?type=release_agreement',
|
||||
method:'GET'
|
||||
}).then(res => {
|
||||
if (res.data.code == 200) {
|
||||
this.viewAgreementcont = res.data.data.content
|
||||
this.show = true
|
||||
}
|
||||
})
|
||||
},
|
||||
agreementbtn(){
|
||||
this.agree = true
|
||||
this.show = false
|
||||
},
|
||||
submitForm(){
|
||||
if(!this.agree){
|
||||
uni.showToast({
|
||||
title: '请先同意发布协议!',
|
||||
icon: 'none'
|
||||
});
|
||||
return
|
||||
}
|
||||
if(this.form.content==''||this.form.media.length==0){
|
||||
uni.showToast({
|
||||
title: '发布内容或图片不能为空!',
|
||||
icon: 'none'
|
||||
});
|
||||
return
|
||||
}
|
||||
if(uni.getStorageSync('is_login')){
|
||||
},
|
||||
getPhoneNumber(e) {
|
||||
let that = this;
|
||||
request({
|
||||
url:'common/post/store',
|
||||
method:'post',
|
||||
data:this.form
|
||||
url:'miniapp/phone',
|
||||
method:'POST',
|
||||
data:{
|
||||
phone_code: e.detail.code,
|
||||
}
|
||||
}).then(res => {
|
||||
uni.showToast({
|
||||
title: res.data.message,
|
||||
icon: 'none'
|
||||
});
|
||||
if(res.data.code ==200){
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/square/index',// 替换为你要跳转的页面路径
|
||||
});
|
||||
}, 1000);
|
||||
if (res.data.code == 200) {
|
||||
this.showlogin = false
|
||||
//返回数据接收成功
|
||||
uni.setStorageSync('is_login', true);
|
||||
}
|
||||
})
|
||||
}else{
|
||||
this.showlogin = true
|
||||
},
|
||||
getcategory(){
|
||||
request({
|
||||
url:'common/post/category/list',
|
||||
method:'GET'
|
||||
}).then(res => {
|
||||
if (res.data.code == 200) {
|
||||
this.categoryOptions = res.data.data.records || [];
|
||||
this.form.category = res.data.data.records[0].name
|
||||
this.form.category_id = res.data.data.records[0].id
|
||||
this.iconurl = res.data.data.records[0].icon_preset_pull
|
||||
}
|
||||
})
|
||||
},
|
||||
getModelOptions(){
|
||||
// 获取型号选项列表,如果后端有接口可以在这里调用
|
||||
// 示例:从接口获取型号列表
|
||||
request({
|
||||
url:'common/sku/preset',
|
||||
method:'GET'
|
||||
}).then(res => {
|
||||
if (res.data.code == 200) {
|
||||
this.modelOptions = res.data.data || [];
|
||||
}
|
||||
})
|
||||
},
|
||||
syncTabbar(){
|
||||
uni.setTabBarItem({ index:0, text:this.$t('tabbar.home') })
|
||||
uni.setTabBarItem({ index:1, text:this.$t('tabbar.square') })
|
||||
uni.setTabBarItem({ index:2, text:this.$t('tabbar.publish') })
|
||||
uni.setTabBarItem({ index:3, text:this.$t('tabbar.mine') })
|
||||
},
|
||||
goBack(){
|
||||
uni.navigateBack()
|
||||
},
|
||||
leftClick(){
|
||||
uni.navigateBack()
|
||||
},
|
||||
onCategoryChange(e){
|
||||
console.log(e)
|
||||
const index = e.detail.value; // picker 返回的 index
|
||||
const selectCity = this.categoryOptions[index]; // 直接取整条数据
|
||||
this.iconurl = selectCity.icon_preset_pull
|
||||
this.form.category = selectCity.name
|
||||
this.form.category_id = selectCity.id
|
||||
},
|
||||
handleContentInput(e){
|
||||
if(e.detail.value.length>this.maxWords){
|
||||
this.form.content = e.detail.value.slice(0,this.maxWords)
|
||||
}
|
||||
},
|
||||
uploadfn(imgUrl){
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: 'https://bsh.info.hb.hnzhwlkj.cn/upload/image?scene=postlist',
|
||||
filePath: imgUrl,
|
||||
name: 'image',
|
||||
header:{'content-type': 'application/x-www-form-urlencoded','Fdesk-Auth-Token': 'Bearer ' + uni.getStorageSync('token'),'Fdesk-Language': uni.getStorageSync('i18locale')?uni.getStorageSync('i18locale'):'zh','Fdesk-Login-Type': 'wechat','Fdesk-System-Code':'wechat'},
|
||||
success: (uploadFileRes) => {
|
||||
const res = JSON.parse(uploadFileRes.data || '{}')
|
||||
if(res && res.data && res.data.href){
|
||||
resolve(res.data.href)
|
||||
}else{
|
||||
reject('上传失败')
|
||||
}
|
||||
},
|
||||
fail: (err) => reject(err)
|
||||
});
|
||||
})
|
||||
},
|
||||
selectMedia(e){
|
||||
const allowCount = this.maxMedia - this.form.media.length
|
||||
if(allowCount <= 0){
|
||||
uni.showToast({
|
||||
title:`最多只能上传${this.maxMedia}张图片`,
|
||||
icon:'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
const tempFilePaths = e.tempFilePaths || (e.tempFiles || []).map(item => item.path || item.url)
|
||||
const paths = tempFilePaths.slice(0, allowCount)
|
||||
if(paths.length === 0){
|
||||
return
|
||||
}
|
||||
Promise.all(paths.map(p => this.uploadfn(p))).then(urls => {
|
||||
urls.forEach(url => {
|
||||
this.form.media.push(url)
|
||||
})
|
||||
}).catch(() => {
|
||||
uni.showToast({
|
||||
title:'图片上传失败,请重试',
|
||||
icon:'none'
|
||||
})
|
||||
})
|
||||
},
|
||||
delfn(e){
|
||||
this.form.media.splice(e.index, 1)
|
||||
},
|
||||
deleteMedia(index){
|
||||
this.form.media.splice(index, 1)
|
||||
},
|
||||
toggleAgreement(){
|
||||
this.agree = !this.agree
|
||||
},
|
||||
viewAgreement(){
|
||||
request({
|
||||
url:'common/agreement?type=release_agreement',
|
||||
method:'GET'
|
||||
}).then(res => {
|
||||
if (res.data.code == 200) {
|
||||
this.viewAgreementcont = res.data.data.content
|
||||
this.show = true
|
||||
}
|
||||
})
|
||||
},
|
||||
agreementbtn(){
|
||||
this.agree = true
|
||||
this.show = false
|
||||
},
|
||||
submitForm(){
|
||||
if(!this.agree){
|
||||
uni.showToast({
|
||||
title: '请先同意发布协议!',
|
||||
icon: 'none'
|
||||
});
|
||||
return
|
||||
}
|
||||
if(this.form.content==''||this.form.media.length==0){
|
||||
uni.showToast({
|
||||
title: '发布内容或图片不能为空!',
|
||||
icon: 'none'
|
||||
});
|
||||
return
|
||||
}
|
||||
this.form.model = this.form.model.map(item => {
|
||||
return item.model
|
||||
})
|
||||
if(uni.getStorageSync('is_login')){
|
||||
request({
|
||||
url:'common/post/store',
|
||||
method:'post',
|
||||
data:this.form
|
||||
}).then(res => {
|
||||
uni.showToast({
|
||||
title: res.data.message,
|
||||
icon: 'none'
|
||||
});
|
||||
if(res.data.code ==200){
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/square/index',// 替换为你要跳转的页面路径
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
})
|
||||
}else{
|
||||
this.showlogin = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user