batchCopyDialog.vue 4.83 KB
<template>
    <d2-dialog btn-ok-label="确定"
               class="relateStore"
               :is-visible.sync="batchCopyVisible"
               title="批量复制"
               width="600px"
               @closeDialog="handleBatchCopyClose"
               @confirmDialog="handleBatchCopyConfirm">
        <el-form ref="batchCopyForm"
                 label-width="120px"
                 :model="selectData"
                 :rules="rules">
            <el-form-item label="业务场景:">
                <el-input v-model="selectedSceneObj.name"
                          disabled
                          style="width: 370px;">
                </el-input>
            </el-form-item>
            <el-form-item label="复制门店:" prop="selectMerchantObj">
                <el-select v-model="selectData.selectMerchantObj"
                           v-el-select-loadmore="interestsLoadmore"
                           collapse-tags
                           filterable
                           multiple
                           placeholder="请选择复制门店"
                           remote
                           :remote-method="remoteMethod"
                           reserve-keyword
                           style="width: 370px;"
                           value-key="merchantId"
                           @visible-change="visibleChange">
                    <el-option v-for="subItem in storeData"
                               :key="subItem.merchantId"
                               :label="subItem.merchantName"
                               :value="subItem" />
                </el-select>
            </el-form-item>
        </el-form>
        <div class="tips">
            说明:批量复制至新门店后,系统自动按操作商品,自动更新补充商品对应的上架门店
        </div>
    </d2-dialog>
</template>

<script>
import { getAccountMerchantList, getList } from "@/api/merchant";
import { sceneList } from "@/common/constants.js";
export default {
	name: "RelateStoreDialog",
	directives: {
		"el-select-loadmore": {
			bind(el, binding) {
				setTimeout(() => {
					const SELECTWRAP_DOM = el.querySelector(
						".el-select-dropdown .el-select-dropdown__wrap",
					);
					SELECTWRAP_DOM.addEventListener("scroll", function () {
						const condition
							= this.scrollHeight - this.scrollTop <= this.clientHeight;
						if (condition) {
							binding.value();
						}
					});
				}, 100);
			},
		},
	},
	props: {
		batchCopyVisible: {
			type: Boolean,
			default: false,
		},
		selectedSceneObj: {
			type: Object,
		},
		baseSceneList: {
			type: Array
		}
	},
	data() {
		return {
			storeData: [],
			// 分页
			total: 0,
			currentPage: 1,
			pageSize: 20,
			searchMerchantName: "",
			sceneList,
			selectData: {},
			rules: { selectMerchantObj: [{ required: true, message: "请选择复制门店", trigger: "blur" }] },
		};
	},

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

	methods: {
		getList() {
			const storeApi = this.filterBaseSceneCodeBySceneType([1, 2, 3]).includes(this.selectedSceneObj?.baseSceneCode) ? getList : getAccountMerchantList; // 售前会员权益升级、售后会员权益升级、售前延保、售后延保场景 上架门店是账户中心所有门店
			storeApi({
				merchantName: this.searchMerchantName,
				currentPage: this.currentPage,
				pageSize: this.pageSize,
				baseSceneCode: this.selectedSceneObj?.baseSceneCode,
			}).then((res) => {
				res?.list?.forEach((val) => { // 账户中心门店返回商户号字段是merchantNo
					if (val.merchantNo)
						val.merchantId = val.merchantNo;
				});
				this.storeData = this.storeData.concat(res.list);
			});
		},

		filterBaseSceneCodeBySceneType(targetTypes) {
			const types = [].concat(targetTypes)
			return this.baseSceneList?.flatMap(val =>
				types.includes(val.sceneType) ? [val.baseSceneCode] : []
			) || []
		},

		// 获取上架门店
		remoteMethod(query) {
			this.searchMerchantName = query;
			this.currentPage = 1;
			this.storeData = [];
			this.getList(); // 请求接口
		},
		visibleChange(data) {
			// 获取焦点重新渲染下拉框数据
			if (data) {
				if (this.searchMerchantName) {
					this.searchMerchantName = "";
					this.currentPage = 1;
					this.storeData = [];
					this.getList();
				}
			}
		},
		// 获取更多上架门店
		interestsLoadmore() {
			setTimeout(() => {
				this.currentPage = this.currentPage + 1;
				if (this.allPages < this.currentPage) {
					this.currentPage = this.allPages;
					return;
				}
				this.getList();
			}, 10);
		},
		handleBatchCopyConfirm() {
			this.$refs.batchCopyForm.validate((valid) => {
				if (valid) {
					this.$emit("handleBatchCopyConfirm", this.selectData?.selectMerchantObj);
				}
			});
		},
		handleBatchCopyClose() {
			this.$emit("handleBatchCopyClose");
		},
	},
};
</script>

<style lang="scss">
.tips {
	font-size: 14px;
	color: #999;
}
</style>