<template>
	<view>
		<view>
			<u-tabs :list="tabsList" :scrollable="false" lineColor="#0A994A" color="#969696"
				activeStyle="color:#15CA65;font-weight: bold;" :current="tabCurrent" @change="tabChange"></u-tabs>
		</view>
		<view style="background-color: #fff;">
			<view v-for="(item,index) in needsList" :key="index" class="my_line"
				style="padding: 24rpx 19rpx;border-bottom: 1px solid #EEEEEE;">
				<text v-if="tabCurrent == 0" class="needs_text">{{item.desc}}</text>
				<text v-if="tabCurrent == 1" class="needs_text">{{item.pname}}</text>
				<view class="time_line">
					<view class="release_time">
						<text>{{item.pub_time}}</text>
					</view>
					<view style="display: flex;">
						<view class="btn" @click="editIdeasAndNeeds(item)">
							<u-icon name="edit-pen" color="#15CA65" size="20"></u-icon>
							<text class="btn_text">修改</text>
						</view>
						<view class="btn" @click="deleteIdeasAndNeeds(item)">
							<u-icon name="trash" color="#15CA65" size="20"></u-icon>
							<text class="btn_text">删除</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-modal :show="showM" :content="content" showCancelButton closeOnClickOverlay="false" @confirm="confirm"
			@cancel="cancel">
		</u-modal>
	</view>
</template>

<script>
	import {
		dateFormatXwDetail
	} from '../../utills/date.js'
	export default {
		data() {
			return {
				id: '',
				showM: false,
				content: '您确定删除吗?',
				tabCurrent: 0,
				type: '',
				desc: '',
				pname: '',
				pub_time: '',
				tabsList: [{
					name: '需求发布'
				}, {
					name: '创意发布'
				}],
				needsList: [{
					id: 1,
					desc: '需求描述需求描述需求描述需求描述需求描述需求描述需求描述需求描述需求描述描述需求描述描...',
					pname: '产品名称产品名称产品名称',
					pub_time: '2022-12-03 09:59',
				}, {
					id: 2,
					desc: '需求描述需求描述需求描述需求描述需求描述需求描述需求描述需求描述需求描述描述需求描述描...',
					pname: '产品名称产品名称产品名称',
					pub_time: '2022-12-03 09:59',
				}]
			}
		},
		onLoad() {
			if (this.tabCurrent == 0) {
				this.type = 2
			} else if (this.tabCurrent == 1) {
				this.type = 1
			}
			this.getIdeasAndNeeds()
		},
		methods: {
			//获取创意发布
			getIdeasAndNeeds() {
				this.$apiServe.getIdeasAndNeeds(this.type).then(res => {
					console.log('获取创意发布&需求发布', res.data);
					let data = res.data.data
					for (const item of data) {
						item.pub_time = dateFormatXwDetail(pub_time)
						this.id = item.id
					}
					// this.productList = data
				}).finally(_ => {

				})
			},
			tabChange(data) {
				this.tabCurrent = data.index
				this.getIdeasAndNeeds()
			},
			//修改我的需求或创意
			editIdeasAndNeeds(item) {
				uni.reLaunch({
					url: '/pages/ideasAndNeeds/ideasAndNeeds?item=' + JSON.stringify(item)
				})
			},
			//删除我的需求或创意
			deleteIdeasAndNeeds(item) {
				this.showM = true
			},
			//删除确认按钮
			confirm() {
				this.showM = false
				// this.$apiServe.deleteIdeasAndNeeds(this.id).then(res => {
				// 	console.log('删除发布', res.data);
				// 	// this.needsList.splice(this.needsList.id, 1)
				// }).finally(_ => {

				// })
			},
			cancel() {
				this.showM = false
			}
		}
	}
</script>

<style lang="scss">
	.u-modal__content {
		padding: 43rpx 104rpx !important;
		text-indent: 25rpx;
	}


	.u-tabs {
		margin-bottom: 10rpx;

		.u-tabs__wrapper__nav {
			background-color: #FFFFFF;

			.u-tabs__wrapper__nav__item {
				padding: 0 !important;
				flex: 1;
			}
		}
	}

	.my_line:last-child {
		border: none !important;
	}

	.needs_text {
		font-size: 30rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #3E3E3E;
		line-height: 42rpx;
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.time_line {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 14rpx;
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;

		.release_time {
			color: #969696;
		}

		.btn {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: 40rpx;

			.u-icon__icon {
				top: 1px !important;
			}

			.btn_text {

				color: #15CA65;
			}
		}
	}
</style>
