relateStoreDialog.vue 6.98 KB
<!-- 关联门店弹窗 -->
<template>
  <d2-dialog btn-ok-label="确定"
             class="relateStore"
             width="70%"
             :is-visible.sync="relateStoreVisible"
             :title="title"
             @closeDialog="handleRelateStoreClose"
             @confirmDialog="handleRelateStoreConfirm">
    <slot />
    <el-row class="tableCon">
      <div class="tableBox left">
        <el-table ref="seletingTable"
                  class="table"
                  height="464px"
                  border
                  :data="selectingData"
                  @select="handleChange"
                  @select-all="handleAll">
          <el-table-column align="center"
                           type="selection"
                           width="55" />
          <template v-for="(item, index) in tablecolumnList">
            <el-table-column v-if="tableHeadItems.includes(item.label)"
                             :key="index"
                             align="center"
                             :label="item.label"
                             :prop="item.prop">
            </el-table-column>
          </template>
        </el-table>
        <el-pagination layout="total, prev, pager, next"
                       background
                       small
                       :current-page.sync="currentPage"
                       :page-size="pageSize"
                       :total="total"
                       @current-change="handleCurrentChange" />
      </div>
      <el-table class="tableBox table"
                height="464px"
                border
                :data="selectedData">
        <el-table-column align="center"
                         label="门店名称"
                         prop="merchantName">
          <template #default="scope">
            <span>{{ scope.row.merchantName }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center"
                         label="门店商户号"
                         prop="merchantId">
          <template #default="scope">
            <span>{{ scope.row.merchantId }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center"
                         label="删除"
                         width="50px">
          <template #default="scope">
            <el-button class="el-icon-delete"
                       type="text"
                       @click="handleDelete(scope.row)" />
          </template>
        </el-table-column>
      </el-table>
    </el-row>
  </d2-dialog>
</template>

<script>
export default {
	name: "RelateStoreDialog",

	props: {
		title: {
			type: String,
			default: "上架门店",
		},
		relateStoreVisible: {
			type: Boolean,
			default: false,
		},
		storeApi: {
			type: Function,
			default: () => {},
		},
		storeSelected: {
			type: Array,
			default: () => [],
		},
		storeSearchForm: {
			type: Object,
			default: () => {},
		},
		selectedBaseSceneCode: {
			type: String,
		},
		isHide: {
			type: Boolean,
			default: false,
		},
		selectedSceneType: {
			type: String,
		},
		page: {
			type: String,
			default: "",
		},
		tableHeadItems: {
			type: Array,
			default: () => {
				return ["门店名称", "门店地址", "门店商户号", "服务对接", "服务对接商户号"];
			},
		},
	},
	data() {
		return {
			tablecolumnList: [{
				label: "门店名称",
				prop: "merchantName",
				align: "center",
			}, {
				label: "门店地址",
				prop: "merchantAddress",
				align: "center",
			}, {
				label: "门店商户号",
				prop: "merchantId",
				align: "center",
			}, {
				label: "服务对接",
				prop: "yqMerchantName",
				align: "center",
			}, {
				label: "服务对接商户号",
				prop: "yqMerchantId",
				align: "center",
			}],
			selectedData: [],
			selectingData: [],
			// 分页
			total: 0,
			currentPage: 1,
			pageSize: 20,
		};
	},

	mounted() {
		this.selectedData = this.storeSelected;
		this.getSelectingList();
	},

	methods: {
		recoverySelection() {
			let exitIds = this.selectedData.map(item => item.merchantId);
			this.selectingData.forEach((item) => {
				exitIds.includes(item.merchantId)
				&& this.$refs.seletingTable.toggleRowSelection(item, true);
			});
		},
		getSelectingList() {
			this.storeApi({
				...this.storeSearchForm,
				currentPage: this.currentPage,
				pageSize: this.pageSize,
				baseSceneCode: this.selectedBaseSceneCode,
				queryMerchantAddr: true,
			}).then((res) => {
				res?.list?.forEach((val) => {
					// 账户中心门店返回商户号字段是merchantNo
					if (val.merchantNo)
						val.merchantId = Number(val.merchantNo);
					val?.sceneList?.forEach((subVal) => {
						if (subVal.scene == this.selectedSceneType) {
							val.yqMerchantId = subVal?.yqMerchant?.merchantId || "-";
							val.yqMerchantName = subVal?.yqMerchant?.merchantName || "-";
						}
					});
				});
				this.selectingData = res.list;
				this.total = res.total;
				this.$nextTick(() => {
					this.recoverySelection();
				});
			});
		},
		handleChange(selection, row) {
			let addOrDelete = !!selection.find(
				item => item.merchantId === row.merchantId,
			);
			row = {
				...row,
				inventoryType: 2,
			};
			addOrDelete
				? this.selectedData.push(row)
				: (this.selectedData = this.selectedData.filter(
						item => item.merchantId !== row.merchantId,
					));
		},
		handleAll(selection) {
			this.selectingData.forEach((item) => {
				if (!item.inventoryType) {
					this.$set(item, "inventoryType", 2);
				}

				let isExit = this.selectedData.findIndex(
					subItem => subItem.merchantId === item.merchantId,
				);
				if (selection.length && isExit === -1) {
					this.selectedData.push(item);
				} else if (!selection.length && isExit !== -1) {
					this.selectedData.splice(isExit, 1);
				}
			});
		},
		handleDelete(row) {
			this.selectedData = this.selectedData.filter(
				item => item.merchantId !== row.merchantId,
			);
			const obj = this.selectingData.find(v => v.merchantId == row.merchantId);
			this.$refs.seletingTable.toggleRowSelection(obj);
		},
		handleCurrentChange(val) {
			this.currentPage = val;
			this.getSelectingList();
		},
		handleRelateStoreConfirm() {
			this.$emit("handleRelateStoreConfirm", this.selectedData);
		},
		handleRelateStoreClose() {
			this.$emit("handleRelateStoreClose");
		},
	},
};
</script>

<style lang="scss">
.relateStore .table {
	margin: 0 auto 20px !important;
	width: 98%;
}
.relateStore .tableCon {
	margin-top: 20px;
	display: flex;
	.tableBox {
		flex: 1;
	}
	.left {
		flex: 1.5 !important;
	}
}
.service-store .relateStore .el-table .cell,
.d2-form .relateStore .el-table .cell {
	line-height: 26px !important;
}
.service-store .relateStore .el-table--medium td,
.d2-form .relateStore .el-table--medium td {
	padding: 6px 8px !important;
}
.relateStore .red {
	color: red;
}
.relateStore .tip-icon {
	position: absolute;
	display: inline-block;
	height: 10px;
	width: 10px;
	line-height: 10px;
	color: #ffffff;
	background-color: red;
	border: 1px solid red;
	border-radius: 50%;
	cursor: pointer;
	font-size: 6px;
	margin-left: 2px;
}
</style>