shortAllocation.vue 9.04 KB
<!-- 短课程配课 -->
<template>
    <div class="short-dialog">
        <baseDialog class="accountDailog"
                    :config="config"
                    :dialog-config="dialogConfig"
                    :is-show.sync="visible"
                    @closeDialog="handleClose"
                    @handleClick="handleConfirm">
            <div class="dialog-content">
                <el-form ref="formRef"
                         :model="configData"
                         :rules="rules">
                    <el-form-item label="开启课程:" label-width="100px">
                        <el-switch v-model="configData.openFlag"
                                   active-value="Y"
                                   inactive-value="N">
                        </el-switch>
                    </el-form-item>
                    <h4 class="group-title">
                        学习条件
                    </h4>
                    <div class="rule-item">
                        <el-form-item label="本周门店渗透率 <"
                                      prop="storePenetrationWeekly">
                            <el-input v-model="configData.storePenetrationWeekly"
                                      placeholder="请输入"
                                      style="width: 120px"
                                      @blur="validateNumber('storePenetrationWeekly', 30, 90)">
                                <template #append>
                                    %
                                </template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label=",且驻店人员上月渗透率 ≤"
                                      prop="storePenetrationMonthly">
                            <el-input v-model="configData.storePenetrationMonthly"
                                      placeholder="请输入"
                                      style="width: 120px"
                                      @blur="validateNumber('storePenetrationMonthly', 30, 90)">
                                <template #append>
                                    %
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                    <div class="rule-item">
                        <el-form-item label="本周驻店接待记录为战败,且质检分低于"
                                      prop="inspectionScore">
                            <el-input v-model="configData.inspectionScore"
                                      placeholder="请输入"
                                      style="width: 80px"
                                      @blur="validateNumber('inspectionScore', 30, 100)">
                            </el-input>
                            <span class="unit-text">分时,开展为期7天短课程学习</span>
                        </el-form-item>
                    </div>
                    <h4 class="group-title">
                        学习要求
                    </h4>
                    <div class="rule-item">
                        <el-form-item label="短课程学习需要在课程发布后" prop="finishTime">
                            <el-input v-model="configData.finishTime"
                                      placeholder="请输入"
                                      style="width: 80px"
                                      @blur="validateNumber('finishTime', 24, 168)">
                            </el-input>
                            <span class="unit-text">小时内完成</span>
                        </el-form-item>
                    </div>
                    <div class="rule-item">
                        <el-form-item label="如果在限时内未完成则">
                            <el-select v-model="configData.punishType" placeholder="请选择">
                                <el-option v-for="item in punishTypeOpt"
                                           :key="item.confId"
                                           :label="item.confValue"
                                           :value="item.confId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </div>
                    <div class="rule-item">
                        <el-form-item label="生效时间为">
                            <el-select v-model="configData.effectiveType"
                                       placeholder="请选择">
                                <el-option v-for="item in effectiveTypeOpt"
                                           :key="item.confId"
                                           :label="item.confValue"
                                           :value="item.confId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </div>
                </el-form>
            </div>
        </baseDialog>
    </div>
</template>

<script>
import { getSopConfig, updateSopConfig } from "@api/serviceCentre";
import { effectiveTypeOpt, punishTypeOpt } from "@/common/constants.js";
import { filterSpecsStr } from "../../../goods/filterOption";

export default {
	props: {
		shortVisible: {
			type: Boolean,
			default: false,
		},
	},
	data() {
		return {
			dialogConfig: {
				title: "短课程配课",
				width: "720px",
			},
			config: {
				showClose: true,
				appendToBody: false, // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
				isShowFooter: true,
				cancel_name: "取 消",
				confirm_name: "提 交",
			},
			punishTypeOpt,
			effectiveTypeOpt,
			rules: {
				storePenetrationWeekly: [
					{ required: true, message: "请输入本周门店渗透率", trigger: "blur" },
				],
				storePenetrationMonthly: [
					{ required: true, message: "请输入上月渗透率", trigger: "blur" },
				],
				inspectionScore: [
					{ required: true, message: "请输入质检分", trigger: "blur" },
				],
				finishTime: [
					{ required: true, message: "请输入短课程学习时间", trigger: "blur" },
				],
			},
			configData: {
				effectiveType: "",
				storePenetrationMonthly: "",
				storePenetrationWeekly: "",
				punishType: "",
				effectiveType: "",
				inspectionScore: "",
				finishTime: "",
				openFlag: "",
			},
		};
	},
	computed: {
		visible: {
			get() {
				return this.shortVisible;
			},
			set(newVal) {
				this.$emit("dialogClose", {
					flag: newVal,
					attrName: "shortVisible",
				});
			},
		},
	},
	created() {
		this.getSopConfigData();
	},
	methods: {
		validateNumber(field, min, max) {
			let value = this.configData[field];
			value = Number.parseInt(value);
			if (isNaN(value))
				value = "";
			// 限制最大值
			if (Number.parseInt(value) > max) {
				value = "";
				this.$message.warning(`输入值不能超过 ${max}`);
			}
			if (Number.parseInt(value) < min) {
				value = "";
				this.$message.warning(`输入值不能小于${min}`);
			}
			this.$set(this.configData, field, value);
		},
		getSopConfigData() {
			getSopConfig({})
				.then((res) => {
					console.log(res, "getSopConfig");
					this.configData = res;
					this.configData.openFlag = this.configData.openFlag == 1 ? "Y" : "N";
				})
				.catch((err) => {
					new Error(err);
				});
		},
		// 提交
		handleConfirm() {
			this.$refs.formRef.validate((valid, invalidFields) => {
				if (valid) {
					let params = {
						storePenetrationWeekly: this.configData.storePenetrationWeekly,
						storePenetrationMonthly: this.configData.storePenetrationMonthly,
						inspectionScore: this.configData.inspectionScore,
						studyDay: this.configData.studyDay,
						punishType: this.configData.punishType,
						finishTime: this.configData.finishTime,
						effectiveType: this.configData.effectiveType,
						openFlag: this.configData.openFlag == "Y" ? 1 : 0,
					};
					updateSopConfig(params)
						.then((res) => {
							console.log(res, "updateSopConfig");
							this.$message.success("修改成功");
							this.handleClose();
						})
						.catch((err) => {
							new Error(err);
						});
				}
			});
		},
		handleClose() {
			this.visible = false;
		},
	},
};
</script>

<style scoped lang="scss">
.short-dialog {
	::v-deep .el-dialog__headerbtn .el-dialog__close {
		color: #333333;
		font-weight: 600;
		font-size: 20px;
	}
	::v-deep .el-form-item__label {
		color: #333333;
		font-size: 16px;
	}
	::v-deep .el-form-item__content {
		display: flex;
	}
	::v-deep .el-divider--horizontal {
		margin: 16px 0;
	}
	::v-deep .el-switch {
		margin-top: 8px;
	}
	::v-deep .el-input-group__append {
		padding: 0 10px;
	}
	.group-title {
		color: #111111;
		font-size: 16px;
		font-weight: 500;
		padding: 10px 0;
		border-bottom: 1px solid #e5e5e5;
	}
	.rule-item {
		display: flex;
		align-items: center;
	}
	.unit-text {
		margin-left: 12px;
		font-size: 16px;
	}
	::v-deep .el-form-item.is-required:not(.is-no-asterisk) > .el-form-item__label:before {
		color: #f5f7fa;
	}
	::v-deep .el-switch__label,
	.el-switch__label.is-active {
		color: #333;
	}
}
</style>