index.vue 8.36 KB
<!-- 服务商管理 -->
<template>
    <d2-container class="service-manage">
        <template #header>
            <div class="header">
                <d2-search ref="showSearch"
                           class="show-search"
                           :search-form="searchForm"
                           :form-data="showFormData" />
                <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 ref="serviceStoreTable"
                      :search-form="searchForm"
                      :table-params="tableParams"
                      :get-list-api="getListApi"
                      :before-search-fn="beforeSearchFn">
                <template #scene-tag="scope">
                    <template v-if="scope.scope.tagNames && scope.scope.tagNames.length">
                        <span v-for="(item, index) in scope.scope.tagNames"
                              :key="index"
                              class="scene-tag">
                            {{ item }}
                        </span>
                    </template>
                    <span v-else>-</span>
                </template>
                <template #statusHtml="scope">
                    <div class="taskStatus">
                        <div class="spot" :class="[scope.scope.status === 1 ? 'greenSpot' : 'ashSpot']"></div>
                        <div>{{ scope.scope.status === 1 ? "启用" : "禁用" }}</div>
                    </div>
                </template>
                <template #auth-button="scope">
                    <el-switch v-model="scope.scope.status"
                               :active-value="1"
                               :inactive-value="0"
                               :disabled="!!scope.scope._statusSwitchLoading"
                               @change="(val) => handleStatusSwitch(val, scope.scope)" />
                </template>
                <template #description-cell="slotProps">
                    <template v-if="getDescriptionText(slotProps.scope)">
                        <el-tooltip effect="dark"
                                    placement="top"
                                    popper-class="manage-scene-desc-tooltip">
                            <template #content>
                                <div class="manage-scene-desc-tooltip__content">
                                    {{ getDescriptionText(slotProps.scope) }}
                                </div>
                            </template>
                            <div class="scene-desc-ellipsis">
                                {{ getDescriptionText(slotProps.scope) }}
                            </div>
                        </el-tooltip>
                    </template>
                    <span v-else>-</span>
                </template>
            </d2-table>
        </div>
    </d2-container>
</template>

<script>
import { disableScene, enableScene, getList, getSceneTags } from "@api/senseManage";
import { mapActions } from "vuex";
import { procureModeList } from "@/common/constants";

export default {
	name: "SenseManage",
	components: {
	},
	data() {
		return {
			procureModeList,
			searchForm: {
				name: "",
				merchantType: [],
			},
			showFormData: [{
				label: "场景名称",
				name: "name",
				type: "input",
				placeholder: "请输入场景名称",
				isClear: true,
				keyFn: this.keyDowmGetList,
			}, {
				label: "标签",
				name: "tagIds",
				type: "select",
				multiple: true,
				collapseTags: true,
				isClear: true,
				optionList: [],
				optionId: "id",
				optionLabel: "name",
				placeholder: "请选择场景标签",
				optionsName: "sceneTagList",
			}],
			getListApi: getList,
			// 表格参数
			tableParams: {
				btnId: new Date().getTime() + Number.parseInt(Math.random() * 1000),
				listName: "list",
				tableOption: true,
				tableColumns: [{
					label: "编号",
					width: 140,
					prop: "num",
				}, {
					label: "场景名称",
					width: 220,
					prop: "name",
				}, {
					label: "业务大类",
					width: 140,
					prop: "bizTypeName",
				}, {
					label: "业务小类",
					width: 200,
					prop: "subTypeName",
				}, {
					label: "标签",
					width: 220,
					prop: "tagNames",
					addHtml: "scene-tag",
				}, {
					label: "描述",
					prop: "description",
					width: "380",
					align: "left",
					addHtml: "description-cell",
				}, {
					label: "状态",
					prop: "status",
					width: 120,
					addHtml: "statusHtml",
				}],
			},
		};
	},

	mounted() {
		this.loadSceneTagOptions();
	},

	methods: {
		...mapActions({
			get: "d2admin/base/get",
			close: "d2admin/page/close",
		}),
		async loadSceneTagOptions() {
			try {
				const res = await getSceneTags({});
				const list = res || [];
				const optionList = (Array.isArray(list) ? list : [])
					.map(it => ({
						id: it?.id,
						name: it?.name,
					}))
					.filter(it => it.id !== undefined && it.name);
				this.showFormData[1].optionList = optionList;
			} catch (e) {
			}
		},
		beforeSearchFn() {
			return new Promise((resolve) => {
				resolve();
			});
		},
		keyDowmGetList() {
			this.$refs.serviceStoreTable.refreshTable();
		},
		handleReset() {
			this.searchForm = {
				name: "",
				merchantType: [],
			};
			this.$refs.serviceStoreTable.refreshTable();
		},
		// 编辑服务商
		handleEdit(row) {
			this.close({ tagName: "/editService" });
			this.$router.push({
				name: "editService",
				params: { serviceMerchantId: row.partnerMerchantId },
			});
		},
		async handleStatusSwitch(val, row) {
			const prevVal = val === 1 ? 0 : 1;
			this.$set(row, "status", prevVal);
			if (!row?.id) {
				this.$message?.error?.("缺少场景ID,无法切换状态");
				return;
			}
			if (val === 0) {
				try {
					await this.$confirm("禁用后,此场景将暂时无法在新门店上架,已上架的门店不受影响,确定继续?", "提示", {
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						type: "warning",
					});
				} catch (e) {
					return;
				}
			}
			this.$set(row, "_statusSwitchLoading", true);
			try {
				if (val === 1) {
					await enableScene({ id: row.id });
				} else {
					await disableScene({ id: row.id });
				}
				this.$set(row, "status", val);
				this.$message?.success?.("操作成功");
			} catch (e) {
				this.$set(row, "status", prevVal);
				this.$message?.error?.(e?.message || "操作失败,请稍后重试");
			} finally {
				this.$set(row, "_statusSwitchLoading", false);
			}
		},
		getSceneTagLabel(row) {
			return row || "-";
		},
		getDescriptionText(row) {
			const v = row?.description;
			if (v === undefined || v === null) {
				return "";
			}
			const s = String(v).trim();
			return s;
		},
	},
};
</script>

  <style lang="scss" scoped>
  ::v-deep .service-manage {
	/*下拉选择框-多选-内容过长-用...代替    begin    */
	.el-tag.el-tag--info {
		background-color: #f4f4f5;
		border-color: #e9e9eb;
		color: #909399;
		max-width: calc(100% - 50px);
		/* white-space: nowrap;
       text-overflow: ellipsis;
       overflow: hidden;*/
	}

	.el-tag.el-tag--info {
		width: calc(100% - 200px);
	}

	.el-tag.el-tag--info .el-select__tags-text {
		width: calc(100% - 20px);
		float: left;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/*下拉选择框-多选-内容过长-用...代替    end    */

	.el-select-dropdown__item {
		width: 395px !important;
	}
}

.scene-tag {
	border-radius: 2px;
	border: 1px solid #e5e5e5;
	background: #f8faff;
	color: #333333;
	font-size: 14px;
	padding: 1px 6px;
	display: inline-block;
	margin-right: 1px;
}

.taskStatus {
	display: flex;
	align-items: center;
	justify-content: center;
}

.scene-desc-ellipsis {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	line-clamp: 2;
	-webkit-line-clamp: 2;
	overflow: hidden;
	text-overflow: ellipsis;
	word-break: break-word;
	line-height: 1.5;
	max-width: 100%;
	cursor: default;
}
</style>

<style lang="scss">
.manage-scene-desc-tooltip {
	max-width: 480px;
}

.manage-scene-desc-tooltip__content {
	white-space: pre-wrap;
	word-break: break-word;
	line-height: 1.5;
}
</style>