StoreConfigTab.vue 8.57 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="['9201007']" />
				</span>
			</d2-table-header>
			<d2-table
				ref="recordTable"
				:search-form="{
					t: searchFormSearch,
				}"
				:table-params="tableParams"
				:get-list-api="getListApi"
				:before-search-fn="beforeSearchFn"
			>
				<template #auth-button="scope">
					<div width="400">
						<span style="margin-right: 10px">
							<auth-button :data="scope.scope" :show-btn-ids="['9201008']" />
						</span>
						<span>
							<auth-button :data="scope.scope" :show-btn-ids="['9201005']" />
						</span>
					</div>
				</template>
			</d2-table>
		</div>

		<glsk-form-dialog
			v-if="dialogVisible"
			:selectVisible="dialogVisible"
			:dialogConfig="dialogConfig"
			label-width="150px"
			defaultWidth="400px"
			:editData="editData"
			:editFormData="editFormData"
			:formRules="formRules"
			:baseData="baseData"
    	:slotArr="slotArr"
			@handleClose="handleDialogClose"
			@handleConfirm="handleDialogConfirm"
		>
			<template slot="pricingSpecialistTips">
				<div style="font-size: 14px; color: #999; margin: -10px 0 10px 150px;">
					此配置用于决定该4S店收取的线索默认分配给哪位总部定价师。
				</div>
			</template>
		</glsk-form-dialog>
	</d2-container>
</template>

<script>
import { getStoreConfigPage, getCarDealerList, getPricingStaffList, addStoreConfig, updateStoreConfig, deleteStoreConfig } from "@/api/usedCarManagement";
import reportTrackFunMixin from '@/mixins/reportTrackFunMixin'
export default {
	name: "StoreConfigTab",
  mixins: [reportTrackFunMixin], // 导入混入
	data() {
		return {
      slotArr: ["pricingSpecialistTips"],
			searchForm: {
				storeName: "",
				pricingSpecialistName: "",
			},
			searchFormSearch: {},
			showFormData: [
				{
					label: "4S店名称",
					name: "storeName",
					type: "input",
					placeholder: "请输入4S店名称",
					maxLength: 50,
				},
				{
					label: "定价师",
					name: "pricingSpecialistName",
					type: "input",
					placeholder: "请输入定价师",
					maxLength: 50,
				},
			],
			getListApi: getStoreConfigPage,
			tableParams: {
				btnId: new Date().getTime() + parseInt(Math.random() * 1000),
				listName: "records",
				tableOption: true,
				tableColumns: [
					{ label: "4S店名称", prop: "storeName", minWidth: "150" },
					{
						label: "总部定价师",
						prop: "pricingSpecialistName",
						minWidth: "160",
					},
					{ label: "操作人", prop: "updatedBy", width: "160" },
					{ label: "操作时间", prop: "updatedDate", width: "168" },
				],
			},
			dialogVisible: false,
			dialogConfig: {
				title: "新增配置",
				okText: "确定",
				cancelText: "取消",
			},
			formRules: {
				storeId: [{ required: true, message: "请选择4S店名称", trigger: "change" }],
				pricingSpecialistId: [{ required: true, message: "请选择关联总部定价师", trigger: "change" }],
			},
			editData: {
				storeId: "",
				storeName: "",
				pricingSpecialistId: "",
				pricingSpecialistName: "",
				staffPhone: "",
			},
			baseData: {
				storeList: [],
				staffList: [],
			},
			editFormData: [
				{
					label: "4S店名称",
					name: "storeId",
					type: "select",
					placeholder: "请选择4S店名称",
					filterable: true,
					optionsName: "storeList",
					optionId: "mainMerchantId",
					optionLabel: "mainMerchantName",
					optionList: [],
					changeAttr: (val, targetItem) => {
						const target = this.baseData.storeList.find((item) => item.mainMerchantId == val);
						this.editData.storeName = target ? target.mainMerchantName : "";
					},
				},
				{
					label: "关联总部定价师",
					name: "pricingSpecialistId",
					type: "select",
					placeholder: "请选择关联总部定价师",
					filterable: true,
					optionsName: "staffList",
					optionId: "uuid",
					optionLabel: "staffName",
					optionList: [],
					changeAttr: (val, targetItem) => {
						const target = this.baseData.staffList.find((item) => item.uuid == val);
						this.editData.pricingSpecialistName = target?.staffName || "";
						this.editData.staffPhone = target?.staffPhone || "";
					}
				},
        {
          label: "",
          name: "pricingSpecialistTips",
          addHtml: "pricingSpecialistTips"
        }
			],
		};
	},
  mounted() {
    this.onPageShow()
  },
  beforeDestroy() {
    this.onPageHide()
  },
	methods: {
		validateOption(val, list, keyField, clearFields) {
			if (!val) return;
			const exists = list.some(item => item[keyField] == val);
			if (!exists) {
				clearFields.forEach(field => {
					this.editData[field] = "";
				});
			}
		},
		validateConfiguredOptions() {
			if (!this.editData.id) return;

			// 校验 4S店 是否存在于下拉列表中
			this.validateOption(this.editData.storeId, this.baseData.storeList, "mainMerchantId", ["storeId", "storeName"]);

			// 校验 总部定价师 是否存在于下拉列表中
			this.validateOption(this.editData.pricingSpecialistId, this.baseData.staffList, "uuid", ["pricingSpecialistId", "pricingSpecialistName", "staffPhone"]);
		},
		fetchOptions() {
			const p1 = getCarDealerList({}).then((res) => {
				this.baseData.storeList = res || [];
				const storeItem = this.editFormData.find(item => item.name === 'storeId');
				if (storeItem) {
					storeItem.optionList = this.baseData.storeList;
				}
			});
			const p2 = getPricingStaffList({}).then((res) => {
				// 为选项拼接手机号
				this.baseData.staffList = (res || []).map(item => {
					return {
						...item,
						staffNameLabel: item.staffName + (item.staffPhone ? `(${item.staffPhone})` : '')
					};
				});
				// 替换 label 为拼接后的字段
				const staffItem = this.editFormData.find(item => item.name === 'pricingSpecialistId');
				if (staffItem) {
					staffItem.optionLabel = 'staffNameLabel';
					staffItem.optionList = this.baseData.staffList;
				}
			});
			return Promise.all([p1, p2]);
		},
		beforeSearchFn() {
			return new Promise((resolve) => {
				this.searchFormSearch = { ...this.searchForm };
				resolve();
			});
		},
		handleReset() {
			this.searchForm = {
				storeName: "",
				pricingSpecialistName: "",
			};
			this.searchFormSearch = { ...this.searchForm };
			this.$refs.recordTable.refreshTable(true, true);
		},
		handleEditConfig(row) {
			const isEdit = row?.id;
			this.dialogConfig.title = isEdit ? "修改配置" : "新增配置";

			this.editData = {
				...(isEdit && { id: row.id }),
				storeId: isEdit ? String(row.storeId || "") : "",
				storeName: row?.storeName || "",
				pricingSpecialistId: row?.pricingSpecialistId || "",
				pricingSpecialistName: row?.pricingSpecialistName || "",
				staffPhone: row?.staffPhone || "",
			};

			this.fetchOptions().then(() => {
				this.validateConfiguredOptions();
				this.dialogVisible = true;
			});
		},
		handleDialogClose() {
			this.dialogVisible = false;
		},
		handleDialogConfirm() {
			const params = { ...this.editData };
			const isEdit = !!params.id;
			const apiFunc = isEdit ? updateStoreConfig : addStoreConfig;

			apiFunc(params).then((res) => {
				let { code, msg } = res.data;
				code == 0
					? this.$message.success("操作成功")
					: this.$message.error(msg || "操作失败");
				if (code == 0) {
					this.handleDialogClose();
					this.$refs.recordTable.refreshTable(true, true);
				}
			});
		},
		handleDelete(row) {
			this.$confirm("是否执行此次操作", "删除提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning",
				closeOnClickModal: false,
			})
				.then(() => {
					deleteStoreConfig({ id: row.id }).then((res) => {
						let { code, msg } = res.data;
						code == 0
							? this.$message.success("操作成功")
							: this.$message.error(msg || "操作失败");
						if (code == 0) {
							this.$refs.recordTable.refreshTable(true, true);
						}
					});
				})
				.catch((err) => {
					console.log(err);
				});
		},
	},
};
</script>

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

	.title {
		color: #333333;
		font-size: 16px;
	}
}
</style>