<template>
	<view class="actorRelease">
		<navbar leftClick @leftClick="$utils.navigateBack" title="演员发布" />
		
		<view class="images box">
			<view class="">
				封面
			</view>
			<uv-upload 
			:fileList="fileListImage" 
			:maxCount="1" 
			multiple 
			width="150rpx" 
			height="150rpx"
			@delete="deleteImage2"
			@afterRead="afterRead2"
			:previewFullImage="true"></uv-upload>
		</view>


		<view class="form">
			<view class="form-item">
				<view class="label">
					标题：
				</view>
				<input type="text" placeholder="请输入标题" v-model="form.title" />
			</view>
			<!-- <view class="form-item">
				<view class="label">
					价格：
				</view>
				<input type="number" placeholder="请输入价格" v-model="form.money" />
			</view> -->
			<!-- <view class="form-item">
				<view class="label">
					地点：
				</view>
				<input type="text" placeholder="请输入地点"/>
			</view>
			<view class="form-item">
				<view class="label">
					时间：
				</view>
				<input type="text" placeholder="请选择时间"/>
			</view> -->
			<!-- <view class="form-item">
				<view class="label">
					联系方式：
				</view>
				<input type="text" placeholder="请输入联系方式" v-model="form.phone" />
			</view> -->
			<view class="form-item-content">
				<view class="label">
					详情介绍：
				</view>
				<view class="textarea">
					<uv-textarea v-model="form.context" :maxlength="200" count placeholder="输入详情介绍"></uv-textarea>
				</view>
			</view>
			<!-- <view class="form-item-content">
				<view class="label">
					发布人：
				</view>
				<view class="textarea">
					<uv-radio-group v-model="form.isUser">
						<uv-radio size="35rpx" 
						icon-size="35rpx" 
						label="本人发布" 
						labelSize="28rpx" name="1">
						</uv-radio>
						<uv-radio size="35rpx" 
						icon-size="35rpx" 
						label="经纪人发布" 
						labelSize="28rpx" name="0">
						</uv-radio>
					</uv-radio-group>
				</view>
			</view> -->
			<!-- <view class="form-item-content">
				<view class="label">
					联系方式是否付费查看（建议付费避免无效联系）
				</view>
				<view class="textarea">
					<uv-radio-group v-model="form.phonePay">
						<uv-radio size="35rpx" icon-size="35rpx" label="是" labelSize="28rpx" name="1">
						</uv-radio>
						<uv-radio size="35rpx" icon-size="35rpx" label="否" labelSize="28rpx" name="0">
						</uv-radio>
					</uv-radio-group>
				</view>
			</view> -->

			<view class="form-item-content">
				<view class="label">
					作品
				</view>
				<view class="upload">
					<uv-upload :fileList="fileList" :maxCount="5" multiple accept="video" width="150rpx" height="150rpx"
						@delete="deleteImage" @afterRead="afterRead" :previewFullImage="true"></uv-upload>
				</view>
			</view>
		</view>

		<submit @submit="submit" @preview="preview" @draft="draft" />
		
		
		<!-- <confirmationPopup
		ref="confirmationPopup"
		title="提示"
		@confirm="pay"
		confirmText="确认支付">
			<view class="confirmationPopup">
				<image src="/static/image/publish/pay.png" 
				style="width: 150rpx;height: 150rpx;"
				mode=""></image>
				<view class="info">
					确认支付{{ topInfo.money }}元，可置顶{{ topInfo.day }}天
				</view>
			</view>
		</confirmationPopup> -->

		<confirmationPopup ref="confirmationPopupUpload" title="提示" confirmText="确认" @confirm="confirm()">
			<view class="confirmationPopup">
				<image src="/static/image/publish/upload.png" style="width: 150rpx;height: 150rpx;" mode=""></image>
				<view class="info">
					已由平台进行审核，时间周期为24小时
				</view>
			</view>
		</confirmationPopup>
	</view>
</template>

<script>
	import submit from '@/components/content/submit.vue'
	import confirmationPopup from '@/components/toast/confirmationPopup.vue'
	import {
		mapState
	} from 'vuex'

	export default {
		components: {
			submit,
			confirmationPopup
		},
		data() {
			return {
				form: {
					title : '',
					context : '',//演员介绍
				},
				fileList: [//代表作
					// {
					// 	url: 'https://cdn.uviewui.com/uview/swiper/2.jpg'
					// },
				],
				fileListImage: [],//封面
				upTopList: [],
			};
		},
		computed : {
			topInfo(){
				for (var i = 0; i < this.upTopList.length; i++) {
					if(this.upTopList[i].id == this.form.topId){
						return this.upTopList[i]
					}
				}
				return {}
			}
		},
		onShow() {
			// this.indexTopPayList()
		},
		methods: {
			// 获取置顶方式
			indexTopPayList() {
				this.$api('indexTopPayList', res => {
					if (res.code == 200) {
						this.upTopList = res.result
					}
				})
			},

			// 删除图片
			deleteImage(e) {
				this.fileList.splice(e.index, 1)
			},
			// 上传作品
			afterRead(e) {
				let self = this
				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self.fileList.push({
							url
						})
					})
				})
			},
			deleteImage2(e) {
				this.fileListImage.splice(e.index, 1)
			},
			afterRead2(e) {
				let self = this
				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self.fileListImage.push({
							url
						})
					})
				})
			},
			pay() {

				let data = {
					...this.form,
					isCard: 1,
					vod : this.fileList.map((item) => item.url).join(","),
					image : this.fileListImage.map((item) => item.url).join(","),
				}

				this.$api('releaseWorks', data,
					res => {
						if (res.code == 200) {
							this.$refs.confirmationPopupUpload.open()
						}
					})
			},
			submit() {
				
				if(this.fileListImage.length == 0){
					return uni.showToast({
						title: '请上传封面',
						icon : 'none'
					})
				}
				
				if(this.fileList.length == 0){
					return uni.showToast({
						title: '请上传作品',
						icon : 'none'
					})
				}
				
				if (this.$utils.verificationAll(this.form, {
						title: '请输入标题',
						context: '请输入介绍',
					})) {
					return
				}
				
				if(this.form.topId){
					// 选择付费模式
					this.$refs.confirmationPopup.open()
				}else{
					// 没有选择付费
					this.pay()
				}
			},
			confirm() {
				// this.$refs.confirmationPopupUpload.close()
				// uni.navigateTo({
				// 	url: "/pages_mine/publish/competition"
				// })
				uni.navigateBack(-1)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.actorRelease {
		background-color: #fff;
		min-height: 100vh;
		font-size: 28rpx;
		padding-bottom: 150rpx;

		/deep/ .uv-radio {
			margin-right: 25rpx;
			margin-top: 10rpx;
		}

		.box {
			padding: 0 20rpx;
		}

		.avatarFace {
			width: 150rpx;
			height: 150rpx;
			// border: 1px solid #000000;
			margin-left: 10rpx;
		}
		
		.upTop{
			margin-top: 40rpx;
			.title{
				padding-top: 20rpx;
				padding-left: 30rpx;
				border-top: 1px solid #00000015;
				display: flex;
				align-items: center;
			}
			.list{
				padding-top: 30rpx;
				width: 100%;
				.item{
					display: flex;
					padding: 20rpx;
					padding-left: 80rpx;
					justify-content: space-between;
					width: 600rpx;
					border-bottom: 1px solid #00000015;
					align-items: center;
				}
			}
		}

		.form {
			.label {
				padding: 20rpx;
			}

			.form-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 20rpx 0;
				padding-right: 30rpx;

				input {
					text-align: right;
					flex: 1;
				}
			}

			.form-item-content {
				padding-right: 30rpx;
				padding-top: 30rpx;

				.textarea {
					padding-left: 20rpx;
				}

				.upload {
					padding-left: 20rpx;
				}
			}
		}

		.confirmationPopup {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 300rpx;

			image {
				margin-top: 40rpx;
			}

			.info {
				margin-top: 40rpx;
				font-size: 26rpx;
			}
		}
	}
</style>