<template>
	<tableComponents
		ref="tableRef"
		:tableData="tableData"
		style="margin-top: 20px"
		@sortChange="sortChange"
		:tableLoading="tableLoading"
		@currentChange="currentChange"
		@sizeChange="sizeChange"
		:showHeader="false"
	>
		<el-table-column prop="title" label="标题" align="left" width="480">
			<template v-slot="scope">
				<div style="display: flex; flex-direction: column; gap: 5px; padding: 10px 0">
					<div>
						<span style="color: red; font-weight: bold; margin-right: 3px" v-if="scope.row.exclusive == 1">[独家]</span>
						<span class="cursor-pointer" @click="goDetail(1, scope.row, true)" v-html="scope.row.title"></span>
					</div>

					<div class="labels" v-if="Session.get('userInfoLocal').userType == '00'">
						<div class="label_item" v-if="scope.row.companyName && scope.row.companyName.length > 0">
							{{ scope.row.companyName }}
						</div>
						<!-- <div v-for="company in scope.row.companys" :key="company" class="label_item">
								{{ company }}
							</div> -->
					</div>

					<div class="labels" v-if="Session.get('userInfoLocal').userType == '00'">
						<!-- <div v-if="scope.row.conceptLabels && scope.row.conceptLabels.length > 0" class="label_item_box">
								<div v-for="item in scope.row.conceptLabels" :key="item" class="label_item" style="background-color: #eee6cd">
									{{ item }}
								</div>
							</div>

							<div v-if="scope.row.industryLabels && scope.row.industryLabels.length > 0" class="label_item_box">
								<div v-for="item in scope.row.industryLabels" :key="item" class="label_item" style="background-color: #cfdcf3">
									{{ item }}
								</div>
							</div> -->

						<div style="background-color: #eee6cd" class="label_item" v-if="scope.row.conceptLabels && scope.row.conceptLabels.length > 0">
							{{ scope.row.conceptLabels[0] }}
						</div>
						<div style="background-color: #cfdcf3" class="label_item" v-if="scope.row.industryLabels && scope.row.industryLabels.length > 0">
							{{ scope.row.industryLabels[0] }}
						</div>
					</div>
				</div>
			</template>
		</el-table-column>

		<el-table-column label="信号规则" align="center" width="120" v-if="Session.get('userInfoLocal').userType == '00'">
			<template v-slot="scope">
				<div v-if="scope.row.ruleName && scope.row.ruleName.length > 0">
					<div v-for="item in scope.row.ruleName" :key="item" class="label_item">
						{{ item }}
					</div>
				</div>
				<div v-else>-</div>
			</template>
		</el-table-column>

		<el-table-column label="媒体来源" align="center" width="120" v-if="Session.get('userInfoLocal').userType == '00'">
			<template v-slot="scope">
				<div v-if="scope.row.sourceName">
					{{ scope.row.sourceName }}
				</div>
				<div v-else>-</div>
			</template>
		</el-table-column>

		<el-table-column prop="status" align="center" width="120">
			<template #header>
				<el-dropdown trigger="click" @command="handleCommand">
					<div class="el-dropdown-link">
						<text style="color: rgba(0, 0, 0, 0.85); font-size: 14px">发布状态</text>
						<el-image :src="icon_table_filter" style="width: 20px; height: 20px"></el-image>
					</div>
					<template #dropdown>
						<div v-if="Session.get('userInfoLocal').userType == '00'">
							<el-dropdown-menu>
								<el-dropdown-item :command="null">全部</el-dropdown-item>
								<el-dropdown-item :command="1">未发布</el-dropdown-item>
								<el-dropdown-item :command="3">审核中</el-dropdown-item>
								<el-dropdown-item :command="4">已二审</el-dropdown-item>
								<el-dropdown-item :command="2">已发布</el-dropdown-item>
								<el-dropdown-item :command="-1">退改中</el-dropdown-item>
							</el-dropdown-menu>
						</div>
						<div v-else>
							<el-dropdown-menu>
								<el-dropdown-item :command="null">全部</el-dropdown-item>
								<el-dropdown-item :command="1" v-if="Session.get('userInfoLocal').userType == '00'">未发布</el-dropdown-item>

								<el-dropdown-item :command="3" v-if="Session.get('userInfoLocal').userType != '01'">审核中</el-dropdown-item>
								<el-dropdown-item :command="4" v-if="Session.get('userInfoLocal').userType == '02' || Session.get('userInfoLocal').userType == '01'"
									>已二审</el-dropdown-item
								>
								<el-dropdown-item :command="2">已发布</el-dropdown-item>
								<el-dropdown-item :command="-1" v-if="Session.get('userInfoLocal').userType == '02' || Session.get('userInfoLocal').userType == '01'"
									>退改中</el-dropdown-item
								>
							</el-dropdown-menu>
						</div>
					</template>
				</el-dropdown>
			</template>
			<template v-slot="scope">
				<!-- 新闻状态 0-草稿 1-未发布 2-已发布 -->
				<div class="r_point" :style="{ color: '#000' }">
					<div class="point" :style="{ backgroundColor: scope.row.status == 2 ? '#52C41A' : '#D9D9D9' }"></div>
					<text v-if="scope.row.status == 0" style="color: rgba(0, 0, 0, 0.65)">草稿</text>
					<text v-if="scope.row.status == 1" style="color: rgba(0, 0, 0, 0.65)">
						{{ scope.row.deleted ? '已删除' : '未发布' }}
					</text>
					<text v-if="scope.row.status == 2" style="color: rgba(0, 0, 0, 0.65)">已发布</text>
					<text v-if="scope.row.status == 3" style="color: rgba(0, 0, 0, 0.65)">审核中</text>
					<text v-if="scope.row.status == 4" style="color: rgba(0, 0, 0, 0.65)">已二审</text>

					<text v-if="scope.row.status == -1 && !scope.row.deleted" style="color: red"> 退改中 </text>
					<text v-if="scope.row.status == -1 && scope.row.deleted"> 已删除 </text>
				</div>
			</template>
		</el-table-column>

		<el-table-column align="center" width="120" prop="submitter" label="编辑">
			<template v-slot="scope">
				{{ scope.row.submitter ? scope.row.submitter : '-' }}
			</template>
		</el-table-column>
		<el-table-column align="center" width="120" prop="submitter" label="二校" v-if="Session.get('userInfoLocal').userType == '01'">
			<template v-slot="scope">
				{{ scope.row.submitterSecond ? scope.row.submitterSecond : '-' }}
			</template>
		</el-table-column>

		<el-table-column align="center" width="120">
			<template #header>
				<el-dropdown trigger="click" @command="handleCommandRating">
					<div class="el-dropdown-link">
						<text style="color: rgba(0, 0, 0, 0.85); font-size: 14px">编辑评分</text>
						<el-image :src="icon_table_filter" style="width: 20px; height: 20px"></el-image>
					</div>
					<template #dropdown>
						<el-dropdown-menu>
							<el-dropdown-item :command="null">全部</el-dropdown-item>
							<el-dropdown-item :command="0">无评分</el-dropdown-item>
							<el-dropdown-item :command="5">5</el-dropdown-item>
							<el-dropdown-item :command="4">4</el-dropdown-item>
							<el-dropdown-item :command="3">3</el-dropdown-item>
							<el-dropdown-item :command="2">2</el-dropdown-item>
							<el-dropdown-item :command="1">1</el-dropdown-item>
						</el-dropdown-menu>
					</template>
				</el-dropdown>
			</template>

			<template v-slot="scope">
				{{ scope.row.rating != 0 && scope.row.rating != null ? scope.row.rating : '-' }}
			</template>
		</el-table-column>

		<el-table-column prop="score" label="资讯评分" sortable="custom" align="center" width="100">
			<template v-slot="scope">
				<div @click="getScoreDetail(scope.row.id)" :class="[{ 'score-active': isAdmin && curScore === scope.row.id }, { 'score-hover': isAdmin }]">
					{{ scope.row.score }}
				</div>
			</template>
		</el-table-column>
		<el-table-column prop="publishTime" label="报道时间" sortable="custom" align="center" />
		<el-table-column prop="updateTime" label="状态变动时间" sortable="custom" align="center">
			<template v-slot="scope">
				<div>
					<div>{{ formatTime(scope.row.updateTime) == formatTime(scope.row.createTime) ? scope.row.publishTime : scope.row.updateTime }}</div>
				</div>
			</template>
		</el-table-column>
		<el-table-column label="操作" align="center" width="250" fixed="right">
			<template v-slot="scope">
				<div class="option">
					<el-button v-if="scope.row.deleted" type="text" style="margin-left: -10px" @click="doRecoverFn(scope.row)">
						<text>恢复</text>
					</el-button>
					<div v-else style="display: flex; gap: 10px; align-items: center">
						<el-button type="text" :disabled="scope.row.status != 2" class="copyBtn" @click="copyUrl(scope.row)">复制</el-button>

						<!-- 新闻状态 0-草稿 | 1-未发布 | 2-已发布 | 3-送审 | 4-已二审 | -1-退改中 -->
						<div v-if="Session.get('userInfoLocal').userType == '00'">
							<!-- 普通账号 -->
							<el-button
								v-if="scope.row.status == 0 || scope.row.status == 1 || scope.row.status == -1"
								type="text"
								@click="goDetail(1, scope.row, false)"
								>编辑</el-button
							>

							<el-button
								v-if="scope.row.status == 0 || scope.row.status == 1 || scope.row.status == -1"
								type="text"
								@click="doApprovalFn(scope.row, scope.row.status)"
								>送审</el-button
							>
							<el-button v-else-if="scope.row.status == 3" type="text" @click="doApprovalFn(scope.row, scope.row.status)">撤审</el-button>

							<el-button
								v-if="scope.row.status == 0 || scope.row.status == 1 || scope.row.status == -1"
								type="text"
								style="color: #ff1818"
								@click="doDeleteNewsFn(scope.row)"
								>删除</el-button
							>
						</div>
						<div v-if="Session.get('userInfoLocal').userType == '02'">
							<el-button v-if="scope.row.status == 4" type="text" @click="doApprovalFn(scope.row, scope.row.status)">撤审</el-button>

							<!-- 二审账号 -->
							<el-button v-if="scope.row.status == 3" type="text" style="color: #ff1818" @click="doNewReturnFn(scope.row)">退改</el-button>

							<el-button v-if="scope.row.status == 3" type="text" @click="goDetail(1, scope.row, false)">编辑</el-button>

							<el-button v-if="scope.row.status == 3" type="text" @click="doNewCheckFn(scope.row)">复审</el-button>

							<el-button type="text" v-if="scope.row.status == 4" @click="doNewsPublishFn(scope.row, 2)">发布</el-button>
						</div>
						<div v-if="Session.get('userInfoLocal').userType == '01'">
							<!-- 终审账号 -->
							<el-button v-if="scope.row.status == 3 || scope.row.status == 4" type="text" @click="goDetail(1, scope.row, false)">编辑</el-button>

							<el-button v-if="scope.row.status == 4" type="text" style="color: #ff1818" @click="doNewReturnFn(scope.row)">退改</el-button>

							<el-button type="text" v-if="scope.row.status == 2" @click="doNewsPublishFn(scope.row, 1)">撤稿</el-button>
							<el-button type="text" v-else-if="scope.row.status != -1 && scope.row.status == 4" @click="doNewsPublishFn(scope.row, 2)"
								>发布</el-button
							>

							<el-button v-if="scope.row.status == 3" type="text" style="color: #ff1818; margin-left: 5px" @click="doNewReturnFn(scope.row)"
								>退改</el-button
							>
						</div>

						<!-- <el-icon size="16" @click="goRecord(scope.row)">
								<Tickets />
							</el-icon> -->
					</div>
					<!-- v-if="isAdmin" -->
					<el-icon
						v-if="isAdmin || Session.get('userInfoLocal').userType == '02' || Session.get('userInfoLocal').userType == '01'"
						size="16"
						@click="goRecord(scope.row)"
						style="margin-left: 10px"
					>
						<Tickets />
					</el-icon>
				</div>
			</template>
		</el-table-column>
	</tableComponents>
</template>

<script setup>
import tableComponents from '/@/components/tableComponents/index.vue';
import { Session } from '/@/utils/storage';

const props = defineProps({
	// 列表内容
	tableData: {
		type: Object,
		default: () => {},
	},
	tableLoading: {
		type: Boolean,
		default: false,
	},
	defaultCurrentPage: {
		type: Number,
		default: 1,
	},
});
</script>

<style scoped lang="scss">
/*表格全选框去除空框*/

.el-table >>> .DisabledSelection .cell .el-checkbox__inner {
	display: none;

	position: relative;
}

/*表格全选框改为：选择*/

.el-table >>> .DisabledSelection .cell:before {
	content: '选择';

	position: absolute;

	left: 7px;
}
</style>
