demingshangjia/pages/release/video.vue

522 lines
12 KiB
Vue
Raw Normal View History

2020-06-12 17:42:23 +08:00
<template>
<view id="release">
<u-form :model="form" ref="uForm">
2020-08-05 17:42:06 +08:00
<u-form-item label="标题" label-position="right"><u-input v-model="form.name" placeholder="请输入标题" /></u-form-item>
<view class="titles">封面</view>
<u-upload
:form-data="coverformdata"
:max-count="1"
:header="header"
name="article_cover"
:action="action"
del-color="#ececec"
upload-text="选择图片"
del-bg-color="#fff"
:file-list="fileListA"
@on-success="uploadcover"
></u-upload>
<view class="titles">视频</view>
<view class="videobox" v-if="videostate == false" @click="uploadvideo">
<u-icon name="plus" class="u-add-btn" size="40"></u-icon>
<view class="videotext">选择视频</view>
</view>
<view class="videobox" v-else @click="uploadvideo"><video :src="videopath" controls></video></view>
<!-- 标签 -->
<view>
<view class="titles">标签</view>
2020-08-10 10:01:10 +08:00
<view class="form-view active" @click="show_add()">+ 新建标签</view>
<view :class="['form-view',item.state == true ? 'active' : '']" v-for="(item, index) in fileListes" :key="index" @click="changeselect(index)">
2020-08-05 17:42:06 +08:00
{{ item.name }}
2020-06-12 17:42:23 +08:00
</view>
2020-08-05 17:42:06 +08:00
</view>
<!-- 简介 -->
<view class="titles">正文</view>
<view class="titles_border"><textarea placeholder="请输入内容..." v-model="form.intro"></textarea></view>
2020-07-30 19:49:12 +08:00
<view class="show_two">
<u-popup v-model="show_two" mode="bottom" :closeable="true">
<view class="title"><text>选择商品</text></view>
<!-- 商品列表 -->
2020-08-05 17:42:06 +08:00
<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll">
2020-08-10 20:24:58 +08:00
<view class="listes_shoping" v-for="(item, index) in list" :key="index">
2020-07-30 19:49:12 +08:00
<view>
<u-checkbox-group>
2020-08-10 20:24:58 +08:00
<u-checkbox
shape="circle"
size="40"
active-color="#FF780F"
v-model="item.checked"
:name="index"
@change="checkboxChange"
></u-checkbox>
2020-07-30 19:49:12 +08:00
</u-checkbox-group>
</view>
<view><image :src="item.goods_image" mode="widthFix"></image></view>
<view class="contentes">{{ item.goods_name }}</view>
</view>
</scroll-view>
<!-- 提交按钮 -->
<view class="u-button" @click="changes()">确定</view>
</u-popup>
<!-- 底部选择商品列表 -->
<view @click="show_two = true">
选择商品
<image class="images" src="../../static/image/tosign/bhottom.png"></image>
</view>
<!-- 选择后的列表 -->
2020-08-05 17:42:06 +08:00
<view class="List_tosign" v-for="list in shoplist">
<view><image :src="list.goods_image" mode="scaleToFill"></image></view>
<view>{{ list.goods_name }}</view>
<view><image src="../../static/image/tosign/delete.png" mode="widthFix" @click="delarr(list.goods_id)"></image></view>
2020-07-30 19:49:12 +08:00
</view>
</view>
2020-08-05 17:42:06 +08:00
<!-- 提交 -->
<u-button class="custom-style" shape="circle" size="default" @click="publish">发表</u-button>
</u-form>
<!-- 添加标签的按钮 -->
<u-popup v-model="show" mode="center" border-radius="14" :closeable="true">
<view class="text">创建属于你的标签吧</view>
<view class="u-inputes"><u-input v-model="tagcontent" /></view>
<u-button class="custom-style-button" shape="circle" size="default" @click="addLiveSpec">确定</u-button>
</u-popup>
<u-toast ref="uToast" />
2020-06-12 17:42:23 +08:00
</view>
</template>
<script>
2020-08-05 17:42:06 +08:00
export default {
data() {
return {
form: {
name: '',
intro: '',
sex: ''
},
coverformdata: {
name: 'article_cover'
2020-06-12 17:42:23 +08:00
},
2020-08-05 17:42:06 +08:00
header: {
Authorization: 'Bearer' + ' ' + uni.getStorageSync('token')
2020-07-30 19:49:12 +08:00
},
2020-08-05 17:42:06 +08:00
// 演示地址,请勿直接使用
action: 'https://dmmall.sdbairui.com/storeapi/Upload/uploadFile',
fileListA: [],
imgarrA: [],
videopath: '', //视频链接
fileListes: [],
show: false,
show_two: false,
arres_list: [],
shoplist: [], //选择商品列表
list: [],
scrollTop: 0,
selectarr: [], //选中标签
tagcontent: '', //新建标签名字
selectvideo: '', //视频名字
videostate: false //视频状态
};
},
onLoad() {
this.getLiveSpec();
this.resetgood();
},
methods: {
// 获取可以推荐的商品
resetgood() {
this.$u.api.canselectgood({}).then(res => {
if (res.data.live_stataes == 0) {
this.$u.route({
url: `/pages/${url}`
});
} else {
let arr = res.data.list;
for (let index in arr) {
arr[index].checked = false;
2020-07-30 19:49:12 +08:00
}
2020-08-05 17:42:06 +08:00
this.list = arr;
}
});
},
// 发布短视频
publish() {
this.$u.api.publishvideo({
article_title: this.form.name,
article_content: this.form.intro,
article_pic: this.imgarrA[0].file_name,
video_path: this.videopath,
goods_id_arr: this.arres_list,
label_arr: this.selectarr
}).then(res => {
if (res.errCode != 0) {
this.$refs.uToast.show({
title: res.message,
type: 'error'
});
} else {
this.$refs.uToast.show({
title: res.message,
type: 'success'
});
setTimeout(function(){
uni.navigateBack({
delta:1
})
},1000)
}
});
},
// 获取商品数组变化
getshoplist() {
let arr = this.arres_list;
let newarr = this.list;
this.shoplist = [];
for (let index in arr) {
for (let i in newarr) {
if (arr[index] == newarr[i].goods_id) {
this.shoplist.push(newarr[i]);
2020-07-30 19:49:12 +08:00
}
2020-08-05 17:42:06 +08:00
}
}
},
// 改变选中状态
changeselect(num) {
if (this.fileListes[num].state == true) {
this.fileListes[num].state = false;
let index = this.selectarr.indexOf(this.fileListes[num].id);
this.selectarr.splice(index, 1);
} else {
this.fileListes[num].state = true;
this.selectarr.push(this.fileListes[num].id);
}
},
// 创建标签
addLiveSpec() {
2020-08-05 20:10:55 +08:00
this.$u.api.createLivesp({
spec_name: this.tagcontent
}).then(res => {
if (res.errCode != 0) {
this.$refs.uToast.show({
title: res.message,
type: 'error'
});
} else {
this.tagcontent = '';
this.show = false;
this.$refs.uToast.show({
title: res.message,
type: 'success'
});
}
});
2020-08-05 17:42:06 +08:00
},
// 获取标签
getLiveSpec() {
let that = this;
this.$u.api.getLiveSpec({}).then(res => {
if (res.errCode != 0) {
this.$refs.uToast.show({
title: res.message,
type: 'error'
});
} else {
let arr = res.data;
for (let index in arr) {
arr[index].state = false;
}
that.fileListes = arr;
}
});
},
// 上传封面
uploadcover(data) {
let obj = data.data;
obj.url = obj.file_path;
this.imgarrA.push(obj);
},
// 上传视频
uploadvideo() {
let url = this.action;
let that = this;
2020-08-10 15:55:21 +08:00
uni.showLoading({
title:"上传中!"
})
2020-08-05 17:42:06 +08:00
uni.chooseVideo({
count: 1,
sourceType: ['camera', 'album'],
success: function(res) {
2020-08-10 14:47:20 +08:00
that.src = res.tempFilePath;
2020-08-05 17:42:06 +08:00
const tempFilePaths = res.tempFilePath;
uni.uploadFile({
url: url, //仅为示例,非真实的接口地址
filePath: tempFilePaths,
name: 'article_video',
formData: {
name: 'article_video'
},
header: {
Authorization: 'Bearer' + ' ' + uni.getStorageSync('token')
},
success: uploadFileRes => {
2020-08-10 14:47:20 +08:00
console.log(uploadFileRes);
2020-08-05 17:42:06 +08:00
let obj = JSON.parse(uploadFileRes.data);
that.videopath = obj.data.url;
that.selectvideo = obj.data.key;
2020-08-10 15:55:21 +08:00
uni.hideLoading()
2020-08-05 17:42:06 +08:00
that.videostate = true;
},
fail: function(error) {
console.log(error);
}
});
}
});
},
// 新建标签
show_add() {
this.show = !this.show;
},
// 选择直播商品点击确定
changes() {
let that = this;
that.show_two = false;
},
// 选中某个复选框时由checkbox时触发
checkboxChange(e) {
2020-08-10 20:24:58 +08:00
let that = this;
let num =Number(e.name)
if (e.value == true) {
2020-08-11 09:41:12 +08:00
that.pushes(that.list[num].goods_id);
2020-08-10 20:24:58 +08:00
that.list[num].checked=true
} else {
2020-08-11 09:41:12 +08:00
that.delarr(that.list[num].goods_id);
2020-08-10 20:24:58 +08:00
that.list[num].checked=false
2020-08-05 17:42:06 +08:00
}
},
// 删除直播商品
delarr(id) {
var that = this;
if (id == '') {
console.log('为空');
} else {
let index = that.arres_list.indexOf(id);
that.arres_list.splice(index, 1);
that.getshoplist();
}
},
// 增加直播商品
pushes(id) {
var that = this;
if (id == '') {
console.log('为空');
} else {
that.arres_list.push(id);
that.getshoplist();
}
2020-06-12 17:42:23 +08:00
}
2020-08-05 17:42:06 +08:00
},
components: {}
};
2020-06-12 17:42:23 +08:00
</script>
<style lang="scss" scoped>
2020-08-05 17:42:06 +08:00
#release {
2020-06-12 17:42:23 +08:00
width: 690rpx;
margin: 0 auto;
2020-08-05 17:42:06 +08:00
.titles_border,
.uni-textarea-compute {
border: 1px #bababa solid !important;
padding: 10rpx;
border-radius: 10rpx;
}
2020-07-30 19:49:12 +08:00
.show_two {
padding: 30rpx 0 70rpx 0;
}
.scroll {
width: 100%;
height: 400px;
}
.u-button {
background: #ff780f;
width: 690rpx;
height: 98rpx;
line-height: 98rpx;
background: rgba(255, 120, 15, 1);
border-radius: 49px;
font-size: 36rpx;
color: #ffffff;
text-align: center;
margin: 0 auto 20rpx;
}
.show_two .title {
width: 100%;
border-bottom: solid 1px #ececec;
margin-bottom: 30rpx;
}
2020-08-05 17:42:06 +08:00
2020-07-30 19:49:12 +08:00
.show_two .title > text {
font-size: 30rpx;
padding: 30rpx;
display: block;
}
.show_two > view {
font-size: 30rpx;
font-weight: 400;
color: rgba(51, 51, 51, 1);
}
2020-08-05 17:42:06 +08:00
2020-07-30 19:49:12 +08:00
.show_two .images {
width: 22rpx;
height: 12rpx;
float: right;
top: 14rpx;
}
.List_tosign {
overflow: hidden;
zoom: 1;
margin-top: 21rpx;
position: relative;
}
.List_tosign > view {
float: left;
}
.List_tosign > view:nth-child(1) {
width: 180rpx;
height: 160rpx;
margin-bottom: 30rpx;
image {
border-radius: 15rpx;
width: 100%;
height: 100%;
}
}
.List_tosign > view:nth-child(2) {
width: 420rpx;
height: 76rpx;
margin: 43rpx 43rpx 0 21rpx;
}
.List_tosign > view:nth-child(3) {
width: 26rpx;
height: 27rpx;
position: absolute;
top: 0;
right: 0;
bottom: 0;
margin: auto;
image {
width: 100%;
height: 100%;
display: block;
}
}
.listes_shoping {
overflow: hidden;
zoom: 1;
margin-bottom: 30rpx;
height: 160rpx;
position: relative;
}
2020-08-05 17:42:06 +08:00
2020-07-30 19:49:12 +08:00
.listes_shoping > view {
float: left;
}
2020-08-05 17:42:06 +08:00
2020-07-30 19:49:12 +08:00
.listes_shoping > view:nth-child(1) {
width: 36rpx;
height: 36rpx;
margin-top: 62rpx;
margin-left: 30rpx;
}
2020-08-05 17:42:06 +08:00
2020-07-30 19:49:12 +08:00
.listes_shoping > view:nth-child(2) {
width: 180rpx;
height: 160rpx;
margin: 0 31rpx 0 19rpx;
}
2020-08-05 17:42:06 +08:00
2020-07-30 19:49:12 +08:00
.listes_shoping > view:nth-child(2) image {
width: 100%;
}
2020-08-05 17:42:06 +08:00
2020-07-30 19:49:12 +08:00
.listes_shoping > view:nth-child(3) {
width: 425rpx;
margin-top: 43rpx;
overflow: hidden;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
2020-08-05 17:42:06 +08:00
.form-view {
2020-08-10 09:56:01 +08:00
background: #CDC7C8;
2020-08-05 17:42:06 +08:00
border-radius: 6rpx;
2020-06-12 17:42:23 +08:00
margin-right: 20rpx;
font-size: 24rpx;
padding: 8rpx 20rpx;
display: inline-block;
margin-bottom: 28rpx;
color: #fff;
}
2020-08-05 17:42:06 +08:00
.active {
2020-08-10 09:56:01 +08:00
background: #FF780F;
2020-08-05 17:42:06 +08:00
}
.titles {
font-size: 30rpx;
font-weight: 400;
color: rgba(51, 51, 51, 1);
2020-06-12 17:42:23 +08:00
margin: 30rpx 0;
}
2020-08-05 17:42:06 +08:00
.videobox {
width: 200rpx;
height: 200rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: #f4f5f6;
margin-left: 10rpx;
border-radius: 10rpx;
}
.videotext {
margin-top: 10rpx;
}
.videobox video {
width: 200rpx;
height: 200rpx;
}
textarea {
2020-06-12 17:42:23 +08:00
font-size: 26rpx;
}
2020-08-05 17:42:06 +08:00
.custom-style {
background: rgba(255, 120, 15, 1) !important;
color: #fff !important;
2020-06-12 17:42:23 +08:00
font-size: 36rpx;
}
2020-08-05 17:42:06 +08:00
.custom-style-button {
background: rgba(255, 120, 15, 1) !important;
color: #fff !important;
2020-06-12 17:42:23 +08:00
font-size: 28rpx;
width: 200rpx;
margin-bottom: 23rpx;
line-height: 60rpx;
height: 60rpx;
}
}
2020-08-05 17:42:06 +08:00
.u-mode-center-box {
2020-06-12 17:42:23 +08:00
padding: 120rpx;
2020-08-05 17:42:06 +08:00
.text {
2020-06-12 17:42:23 +08:00
font-size: 30rpx;
margin-top: 74rpx;
text-align: center;
font-weight: 500;
color: #333;
}
}
2020-08-05 17:42:06 +08:00
.u-inputes {
2020-06-12 17:42:23 +08:00
margin: 30rpx 0;
border: 1px #ececec solid;
padding-left: 14rpx;
width: 420rpx;
}
</style>