OneCustomerGroupTab.vue 8.4 KB
<template>
	<d2-container class="container">
		<template #header>
			<div class="header">
				<d2-search
					ref="showSearch"
					class="show-search"
					:search-form="searchForm"
					:form-data="showFormData"
					label-width="100px"
				/>
				<div class="up-btns">
					<el-button :id="tableParams.btnId" size="small" type="primary">
						查询
					</el-button>
					<el-button size="small" @click="handleReset"> 重置 </el-button>
				</div>
			</div>
		</template>
		<div class="d2-container-content">
			<d2-table-header :left-span="12">
				<span slot="left" class="title">群列表</span>
				<span style="display: inline-block; margin-right: 10px">
					<auth-button category="Button" :show-btn-ids="['9201001']" />
				</span>
				<span style="display: inline-block">
					<auth-button category="Button" :show-btn-ids="['9201002']" />
				</span>
			</d2-table-header>
			<d2-table
				ref="recordTable"
				:search-form="{
					t: searchFormSearch,
				}"
				:table-params="tableParams"
				:get-list-api="getListApi"
				:before-search-fn="beforeSearchFn"
				@selectionTable="handleSelectionTable"
				@setTableFinishFun="setTableFinishFun"
			>
				<template slot="remark" slot-scope="scope">
					<el-tooltip
						v-if="scope.scope.remark"
						placement="top"
						:content="scope.scope.remark"
					>
						<div class="line-clamp-2">{{ scope.scope.remark || "-" }}</div>
					</el-tooltip>
					<div v-else>-</div>
				</template>
				<template #auth-button="scope">
					<div width="400">
						<span style="margin-right: 10px">
							<auth-button :data="scope.scope" :show-btn-ids="['9201003']" />
						</span>
						<span style="margin-right: 10px">
							<auth-button :data="scope.scope" :show-btn-ids="['9201004']" />
						</span>
						<span>
							<auth-button :data="scope.scope" :show-btn-ids="['9201005']" />
						</span>
					</div>
				</template>
			</d2-table>
		</div>
	</d2-container>
</template>

<script>
import { deepClone } from "@/common/util";
import { getLiveCodePage, deleteLiveCode } from "@/api/usedCarManagement";
import reportTrackFunMixin from '@/mixins/reportTrackFunMixin'
export default {
	name: "OneCustomerGroupTab",
  mixins: [reportTrackFunMixin], // 导入混入
	data() {
		return {
			searchForm: {
				liveName: "",
				remark: "",
				createdBy: "",
			},
			searchFormSearch: {},
			showFormData: [
				{
					label: "活码名称",
					name: "liveName",
					type: "input",
					placeholder: "请输入活码名称",
					maxLength: 50,
				},
				{
					label: "备注",
					name: "remark",
					type: "input",
					placeholder: "请输入备注",
					maxLength: 50,
				},
				{
					label: "创建人",
					name: "createdBy",
					type: "input",
					placeholder: "请输入创建人",
					maxLength: 50,
				},
			],
			selectedList: [],
			getListApi: getLiveCodePage,
			tableParams: {
				btnId: new Date().getTime() + parseInt(Math.random() * 1000),
				listName: "records",
				tableOption: true,
				mutiSelectUniqueKey: "id",
				mutiSelectName: "recordsMutiTable",
				tableColumns: [
					{ label: "活码名称", prop: "liveName", minWidth: "150" },
					{ label: "备注", prop: "remark", minWidth: "120", addHtml: "remark" },
					{ label: "群总数", prop: "groupCount", width: "100" },
					{
						label: "已接待客户群",
						prop: "occupiedGroupCount",
						width: "120",
					},
					{
						label: "可接待客户群",
						prop: "idleGroupCount",
						width: "120",
					},
					{ label: "创建时间", prop: "createdDate", width: "80" },
					{ label: "创建人", prop: "createdBy", minWidth: "150" },
				],
			},
		};
	},
  mounted() {
    this.onPageShow()
  },
  beforeDestroy() {
    this.onPageHide()
  },
	methods: {
		beforeSearchFn() {
			return new Promise((resolve) => {
				this.searchFormSearch = { ...this.searchForm };
				let selectedData =
					this.$refs?.recordTable?.mutiSelectArr[
						this.tableParams.mutiSelectName
					] || [];
				const list = this.$refs.recordTable.data || [];
				let deleteIds = [];
				this.selectedList.forEach((item) => {
					if (
						!list?.map((k) => k.id).includes(item.id) &&
						!selectedData?.map((k) => k.id).includes(item.id)
					) {
						selectedData.push(item);
					}
					if (
						list?.map((k) => k.id).includes(item.id) &&
						!selectedData?.map((k) => k.id).includes(item.id)
					) {
						deleteIds.push(item.id);
					}
				});
				deleteIds.forEach((item) => {
					const idx = selectedData.findIndex((k) => k.id == item);
					if (idx !== -1) {
						selectedData.splice(idx, 1);
					}
				});
				this.selectedList = deepClone(selectedData);
				resolve();
			});
		},
		handleReset() {
			this.searchForm = {
				liveName: "",
				remark: "",
				createdBy: "",
			};
			this.searchFormSearch = { ...this.searchForm };
			this.clearMutiSelect = true;
			this.$refs.recordTable.refreshTable(true, true);
		},
		handleEditGroupCode(row) {
			const query = {
				optType: row ? "update" : "add",
			};
			if (row) {
				query.id = row?.id || "";
			}
			this.$router.push({
				name: "createGroupCode",
				query,
			});
		},

		handleSelectionTable() {},

		setTableFinishFun(data) {
			this.$nextTick(() => {
				if (this.clearMutiSelect) {
					this.selectedList = [];
					this.clearMutiSelect = false;
					this.$refs.recordTable.$refs[
						this.tableParams.mutiSelectName + "MutiTable"
					].clearSelection();
				}
				this.recoverySelection(data);
			});
		},
		recoverySelection(list) {
			if (this.selectedList.length) {
				this.selectedList.forEach((row) => {
					const obj = this.$refs.recordTable.data.find(
						(item) => item.id == row.id
					);
					obj &&
						this.$refs.recordTable.$refs[
							this.tableParams.mutiSelectName + "MutiTable"
						].toggleRowSelection(obj, true);
				});
			}
		},
		handleDownload(row) {
			if (!row.defaultQrCodeUrl) {
				this.$message.error("该群未配置二维码");
				return;
			}
			let a = document.createElement("a");
			a.setAttribute("id", "exportToExport");
			a.setAttribute("href", row.defaultQrCodeUrl || "");
			a.setAttribute("target", "_blank");
			document.body.appendChild(a);
			a.click();
		},

		getMutiDate() {
			console.log(this.$refs.recordTable);
			let selectedData =
				this.$refs.recordTable.mutiSelectArr[this.tableParams.mutiSelectName] ||
				[];
			let deleteIds = [];
			this.selectedList.forEach((item) => {
				if (
					!this.$refs.recordTable.data.map((k) => k.id).includes(item.id) &&
					!selectedData.map((k) => k.id).includes(item.id)
				) {
					selectedData.push(item);
				}
				if (
					selectedData?.map((k) => k.id).includes(item.id) &&
					!selectedData?.map((k) => k.id).includes(item.id)
				) {
					deleteIds.push(item.id);
				}
			});
			deleteIds.forEach((item) => {
				const idx = selectedData.findIndex((k) => k.id == item);
				if (idx !== -1) {
					selectedData.splice(idx, 1);
				}
			});
			return selectedData;
		},

		executeDeleteAction(params) {
			deleteLiveCode(params).then((res) => {
				let { code, msg } = res.data;
				code == 0
					? this.$message.success("操作成功")
					: this.$message.error(msg || "操作失败");
				if (code == 0) {
					this.clearMutiSelect = true;
					this.$refs.recordTable.refreshTable(true, true);
				}
			});
		},
		handleDelete(row) {
			this.$confirm("是否执行此次操作", "删除提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning",
				closeOnClickModal: false,
			})
				.then(() => {
					this.executeDeleteAction({ ids: [row.id] });
				})
				.catch((err) => {
					console.log(err);
				});
		},
		handleBatchDelete() {
			this.selectedList = this.getMutiDate();
			if (this.selectedList.length == 0) {
				this.$message.error("请选择要删除的群");
				return;
			}
			console.log(this.selectedList);
			this.$confirm("是否执行此次操作", "批量删除提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning",
				closeOnClickModal: false,
			})
				.then(() => {
					this.executeDeleteAction({
						ids: this.selectedList.map((item) => item.id),
					});
				})
				.catch((err) => {
					console.log(err);
				});
		},
	},
};
</script>

<style lang="scss" scoped>
.container {
	margin-top: 88px;

	.title {
		color: #333333;
		font-size: 16px;
	}

	.tooltip-content {
		max-height: 300px;
		overflow-y: scroll;
	}

	.line-clamp-2 {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-overflow: ellipsis;
		word-break: break-all;
	}
}
</style>