Files
car-system-app/pages/driver/index/post.vue
2024-07-24 15:49:46 +08:00

285 lines
6.9 KiB
Vue

<template>
<view>
<view class="navbar-box fixed-top">
<!-- #ifdef MP-WEIXIN -->
<view :style="{height: `${$u.sys().statusBarHeight}px;`}" />
<!-- #endif -->
<!-- #ifdef APP -->
<view :style="`height: ${$u.sys().statusBarHeight}px;`" />
<!-- #endif -->
<view class="navbar-title text-center rel">
<view class="back nav-item abs" @click="navBackFn">
<u-icon name="arrow-left" size="22" />
</view>
<text class="text">发帖子</text>
<view class="btn abs nav-item">
<u-button @click="issueFn" :disabled="buttFlag"
:customStyle="{width: '144rpx', height: '56rpx', fontSize: '24rpx'}"
color="#13AFA8">发布</u-button>
</view>
</view>
</view>
<!-- 防塌陷 -->
<view class="">
<!-- #ifdef MP-WEIXIN -->
<view :style="{height: `${$u.sys().statusBarHeight}px;`}" />
<!-- #endif -->
<!-- #ifdef APP -->
<view :style="`height: ${$u.sys().statusBarHeight}px;`" />
<!-- #endif -->
<view class="" style="height: 88rpx;" />
</view>
<view class="textarea-box">
<textarea :confirm-hold="true" v-model="content" :placeholder="issueType==2?'请书写您的心情!!!':'请输入你的内容'"
@confirm="confirmFn" style="width: 750rpx;padding:24rpx"></textarea>
<!-- <u-textarea border="none" v-model="content" autoHeight maxlength="-1" @confirm="confirmFn"
:placeholder="issueType==2?'请书写您的心情!!!':'请输入你的内容'"></u-textarea> -->
</view>
<view class="upload-image-box flex-wrap align-center" v-if="issueType==1">
<view class="upload-image-item rel" :style="{marginRight: index%3==2 ? '0' : '24rpx'}"
v-for="(item,index) in picList" :key="index">
<image class="upload-image" :src="item" mode=""></image>
<image class="clear abs" src="@/static/images/app/serve/realname_clea.png" @click="DelPic('faultImage')"
mode=""></image>
</view>
<view class="upload-image-item" @click="scanQRCode">
<image class="upload-image" src="@/static/images/app/serve/realname_upload.png" mode=""></image>
</view>
</view>
<view v-else-if="issueType==0" class="video rel">
<view style="margin-bottom: 16rpx;">上传视频</view>
<image class="video-image" v-if="!videoImage" src="@/static/images/icon/plus_box.png" mode=""
@click="scanQRCode"></image>
<video v-else :src="videoImage"
:poster="`${videoImage}?x-oss-process=video/snapshot,t_1000,m_fast,ar_auto`"></video>
<image v-if="videoImage" @click="videoImage=''" class="clear abs"
src="@/static/images/app/serve/realname_clea.png" mode=""></image>
</view>
<yk-authpup ref="authpup" type="top" @changeAuth="authorizedFn" permissionID="CAMERA"></yk-authpup>
</view>
</template>
<script>
import ykAuthpup from "@/components/yk-authpup/yk-authpup";
import {
plazaNoteAdd
} from "@/api/discover/discover.js"
export default {
data() {
return {
selectImageShow: false,
picList: [],
content: '',
//分类id
categoryId: 1,
//issueType 0:视频 1:图片
issueType: 0,
//视频
videoImage: '',
//视频宽高
videoInfo: {},
mobileType: {},
buttFlag: false,
city:''
};
},
methods: {
//点击完成
confirmFn(e) {
e.preventDefault();
},
//发布
issueFn() {
this.buttFlag = true
uni.showLoading({
title: '发布中...'
});
let obj = {
content: this.content,
image: this.picList.join(','),
replyStatus: 1,
type: 1,
categoryId: this.categoryId,
video: this.videoImage,
cover: this.videoImage,
wide: this.videoInfo.width,
high: this.videoInfo.height,
city:this.city,
}
// console.log(obj);
plazaNoteAdd(obj).then(res => {
this.buttFlag = false
if (res.data.image != '') {
res.data.image = res.data.image.split(",")
} else {
res.data.image = []
}
if (Number(res.data.wide) > Number(res.data.high)) {
let num = 686 / uni.$u.getPx(`${res.data.wide}rpx`)
res.data.wide = uni.$u.getPx(`${res.data.wide}rpx`) * num + 'rpx'
res.data.high = uni.$u.getPx(`${res.data.high}rpx`) * num + 'rpx'
} else {
let num = 302 / uni.$u.getPx(`${res.data.wide}rpx`)
res.data.wide = uni.$u.getPx(`${res.data.wide}rpx`) * num + 'rpx'
res.data.high = uni.$u.getPx(`${res.data.high}rpx`) * num + 'rpx'
}
console.log('发布内容', res);
uni.setStorageSync('trends_info', res.data);
uni.setStorageSync('video_info', {});
uni.hideLoading();
uni.navigateBack()
})
},
//传视频
getVideo() {
this.$util.uploadVideo({},
false,
true,
res => {
console.log(res.data);
uni.hideLoading();
this.videoInfo = uni.getStorageSync('video_info');
console.log('视频信息', this.videoInfo);
this.videoImage = res.data
});
},
scanQRCode() {
if (this.mobileType.platform != 'ios') {
this.$refs['authpup'].open()
} else {
this.authorizedFn()
}
},
// 已授权执行方法
authorizedFn() {
if (this.issueType == 1) {
this.getImage()
} else {
this.getVideo()
}
},
//传图片
getImage() {
this.$util.uploadImageOne({
count: 9,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
dir: 'lxkimage/public/product/'
}, null, res => {
this.picList.push(res.data)
uni.hideLoading();
});
},
DelPic(index) {
this.picList.splice(index, 1)
},
//返回
navBackFn() {
uni.navigateBack()
}
},
onLoad(options) {
this.categoryId = options.type
this.issueType = options.issueType
this.mobileType = uni.getStorageSync('appDetail')
uni.getLocation({
type: 'gcj02',
geocode: true,
success: res => {
this.city=res.address.city
},
fail: err => {
// console.log('报错', err);
}
})
}
}
</script>
<style lang="scss">
.video {
padding: 0 48rpx;
// border: 1rpx solid #999;
.clear {
top: -16rpx;
right: 32rpx;
width: 32rpx;
height: 32rpx;
}
.video-image {
width: 202rpx;
height: 202rpx;
border-radius: 8rpx;
}
}
.navbar-box {
border-bottom: 1rpx solid #eee;
.navbar-title {
width: 750rpx;
line-height: 88rpx;
.back {
left: 24rpx;
}
.text {
color: #222222;
font-size: 32rpx;
}
.btn {
// #ifdef APP
right: 34rpx;
// #endif
// #ifdef MP-WEIXIN
right: 200rpx;
// #endif
top: 50%;
transform: translateY(-50%);
}
.nav-item {
top: 50%;
transform: translateY(-50%);
}
}
}
.textarea-box {
// padding: 0 16rpx 24rpx 16rpx;
// width: 750rpx;
// min-height: 434rpx;
// border: 1rpx solid #F00;
}
.upload-image-box {
padding: 0 48rpx;
width: 750rpx;
.upload-image-item {
margin-bottom: 24rpx;
width: 202rpx;
height: 202rpx;
}
.upload-image {
width: 202rpx;
height: 202rpx;
border-radius: 8rpx;
}
.clear {
top: -16rpx;
right: -16rpx;
width: 32rpx;
height: 32rpx;
}
}
</style>