abnormalFlowProcessDrawer.vue 12.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
<template>
  <el-drawer class="abnormal-flow-drawer"
             size="60%"
             :before-close="handleClose"
             :visible.sync="drawerVisible"
             :wrapper-closable="false">
    <div slot="title">
      异常流水处理详情
    </div>
    <div v-loading="loading"
         class="drawer-body">
      <template v-if="detailInfo">
        <DetailComp label-width="120px"
                    :config-data="flowInfoConfig"
                    :detail-info="detailInfo">
        </DetailComp>
        <DetailComp label-width="120px"
                    :config-data="reportInfoConfig"
                    :detail-info="detailInfo">
        </DetailComp>
        <div class="section-block">
          <div class="section-title">
            区域经理审批
          </div>
          <div class="section-subtitle">
            (第一轮审批)
          </div>
          <DetailComp label-width="120px"
                      :config-data="firstRoundConfig"
                      :detail-info="detailInfo">
          </DetailComp>
        </div>
        <div v-if="showSecondRoundSection"
             class="section-block">
          <div class="section-title">
            后台审批
          </div>
          <div class="section-subtitle">
            (第二轮审批)
          </div>
          <template v-if="drawerMode === 'approve'">
            <el-form ref="approveFormRef"
                     class="approve-form"
                     label-width="120px"
                     :model="approveForm"
                     :rules="currentApproveRules">
              <el-form-item label="审批结果:"
                            prop="auditResult">
                <el-radio-group v-model="approveForm.auditResult">
                  <el-radio :label="1">
                    审批通过
                  </el-radio>
                  <el-radio :label="2">
                    审批驳回
                  </el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="审批意见:"
                            prop="auditRemark">
                <el-input v-model="approveForm.auditRemark"
                          maxlength="200"
                          placeholder="请输入审批意见,至少10个字"
                          type="textarea"
                          show-word-limit
                          :rows="4">
                </el-input>
              </el-form-item>
              <el-form-item v-if="showExtensionDeadline"
                            label="延期截止时间:"
                            prop="extensionDeadline">
                <el-date-picker v-model="approveForm.extensionDeadline"
                                placeholder="请选择延期截止时间"
                                style="width: 100%"
                                type="date"
                                value-format="yyyy-MM-dd"
                                :picker-options="extensionDeadlinePickerOptions">
                </el-date-picker>
                <div class="form-tip">
                  根据异常类型默认延期3天,可修改
                </div>
              </el-form-item>
            </el-form>
          </template>
          <template v-else>
            <DetailComp label-width="120px"
                        :config-data="secondRoundReadConfig"
                        :detail-info="detailInfo">
            </DetailComp>
          </template>
        </div>
      </template>
    </div>
    <div class="drawer-footer">
      <el-button @click="handleClose">
        {{ readonly ? "关闭" : "取消" }}
      </el-button>
      <el-button v-if="!readonly && drawerMode === 'approve'"
                 type="primary"
                 :loading="submitting"
                 @click="handleSubmit">
        提交审批
      </el-button>
    </div>
  </el-drawer>
</template>

<script>
import {
	approvePcAbnormalFlowDeclaration,
	getPcAbnormalFlowDeclarationDetail,
} from "@/api/finance";
import { afterRangePickerOptions } from "@/components/glsx-combi-form/common";
import {
	getAbnormalTypeLabel,
	getDefaultExtensionDate,
	getDrawerMode,
	mapApproveFormToApi,
	mapPcDeclarationDetail,
	shouldShowSecondRoundSection,
} from "../constants/abnormalFlow";
import DetailComp from "./detailComp.vue";

function formatMoney(val) {
	if (val === null || val === undefined || val === "") {
		return "-";
	}
	return `¥${val}`;
}

const STATUS_COLOR_MAP = {
	yellowSpot: "#E6A23C",
	greenSpot: "#67C23A",
	redSpot: "#F56C6C",
	ashSpot: "#909399",
};

export default {
	name: "AbnormalFlowProcessDrawer",
	components: {
		DetailComp,
	},
	props: {
		visible: {
			type: Boolean,
			default: false,
		},
		rowData: {
			type: Object,
			default: null,
		},
		readonly: {
			type: Boolean,
			default: false,
		},
	},
	data() {
		const validateRemark = (rule, value, callback) => {
			if (!value || value.trim().length < 10) {
				callback(new Error("审批意见至少10个字"));
				return;
			}
			callback();
		};
		const validateExtension = (rule, value, callback) => {
			if (this.approveForm.auditResult === 1 && !value) {
				callback(new Error("请选择延期截止时间"));
				return;
			}
			callback();
		};
		return {
			loading: false,
			submitting: false,
			detailInfo: null,
			extensionDeadlinePickerOptions: afterRangePickerOptions,
			validateRemark,
			validateExtension,
			approveForm: {
				auditResult: 1,
				auditRemark: "",
				extensionDeadline: getDefaultExtensionDate(3),
			},
			flowInfoConfig: [
				{
					title: "流水信息",
					infoData: [
						{ title: "交易参考号", key: "tradeNo", col: 12 },
						{
							title: "原支付金额",
							key: "totalPrice",
							col: 12,
							formatter: info => formatMoney(info.totalPrice),
						},
						{
							title: "结余金额",
							key: "notRefundedTotalPrice",
							col: 12,
							formatter: info => formatMoney(info.notRefundedTotalPrice),
						},
						{ title: "终端编码", key: "posTrmNo", col: 12 },
						{ title: "支付时间", key: "payDate", col: 12 },
						{ title: "所属园区店", key: "yqMerchantName", col: 12 },
						{ title: "支付渠道", key: "payChannel", col: 12 },
						{ title: "收款来源", key: "payTypeLabel", col: 12 },
						{
							title: "分账状态",
							key: "distributionStatusLabel",
							col: 12,
						},
						{ title: "所属流量方", key: "trafficMerchantName", col: 12 },
						{ title: "退款状态", key: "refundStatusLabel", col: 12 },
					],
				},
			],
			reportInfoConfig: [
				{
					title: "驻店报备信息",
					infoData: [
						{ title: "驻店姓名", key: "reporterName", col: 12 },
						{ title: "报备提交时间", key: "reportTime", col: 12 },
						{
							title: "异常类型",
							key: "abnormalTypeLabel",
							col: 12,
							formatter: info =>
								info.abnormalTypeLabel
								|| getAbnormalTypeLabel(info.abnormalType),
						},
						{ title: "报备备注", key: "reportRemark", col: 24 },
						{ title: "上传凭证", key: "voucherList", col: 24, type: "imgList" },
					],
				},
			],
			firstRoundConfig: [
				{
					infoData: [
						{
							title: "审批状态",
							key: "firstRoundStatusLabel",
							col: 12,
							className: (info) => {
								const meta = info.firstRoundStatusMeta;
								return STATUS_COLOR_MAP[meta?.spotClass] || STATUS_COLOR_MAP.ashSpot;
							},
						},
						{ title: "审批人", key: "firstRoundApprover", col: 12 },
						{ title: "审批时间", key: "firstRoundTime", col: 12 },
						{ title: "审批意见", key: "firstRoundRemark", col: 24 },
					],
				},
			],
			secondRoundReadConfig: [
				{
					infoData: [
						{
							title: "审批状态",
							key: "secondRoundStatusLabel",
							col: 12,
							className: (info) => {
								const meta = info.secondRoundStatusMeta;
								return STATUS_COLOR_MAP[meta?.spotClass] || STATUS_COLOR_MAP.ashSpot;
							},
						},
						{ title: "审批人", key: "secondRoundApprover", col: 12 },
						{ title: "审批时间", key: "secondRoundTime", col: 12 },
						{ title: "审批意见", key: "secondRoundRemark", col: 24 },
						{ title: "延期截止时间", key: "extensionDeadline", col: 12 },
					],
				},
			],
		};
	},
	computed: {
		drawerVisible: {
			get() {
				return this.visible;
			},
			set(val) {
				this.$emit("update:visible", val);
			},
		},
		drawerMode() {
			if (this.readonly) {
				return "view";
			}
			return getDrawerMode(this.detailInfo);
		},
		showSecondRoundSection() {
			if (!this.detailInfo) {
				return false;
			}
			return shouldShowSecondRoundSection(this.detailInfo.approvalStatus);
		},
		showExtensionDeadline() {
			return this.approveForm.auditResult === 1;
		},
		currentApproveRules() {
			const rules = {
				auditResult: [
					{ required: true, message: "请选择审批结果", trigger: "change" },
				],
				auditRemark: [
					{ required: true, validator: this.validateRemark, trigger: "blur" },
				],
			};
			if (this.showExtensionDeadline) {
				rules.extensionDeadline = [
					{ validator: this.validateExtension, trigger: "change" },
				];
			}
			return rules;
		},
	},
	watch: {
		visible(val) {
			if (val && this.rowData) {
				this.loadDetail();
			}
		},
		"approveForm.auditResult": {
			handler(val) {
				if (val === 1) {
					if (!this.approveForm.extensionDeadline) {
						this.approveForm.extensionDeadline = getDefaultExtensionDate(3);
					}
				} else if (val === 2) {
					this.approveForm.extensionDeadline = "";
				}
				this.$nextTick(() => {
					if (this.$refs.approveFormRef) {
						this.$refs.approveFormRef.clearValidate("extensionDeadline");
					}
				});
			},
		},
	},
	methods: {
		async loadDetail() {
			if (!this.rowData || !this.rowData.declarationId) {
				this.$message.warning("暂无报备记录,无法加载详情");
				this.handleClose();
				return;
			}
			this.loading = true;
			try {
				const res = await getPcAbnormalFlowDeclarationDetail({
					id: this.rowData.declarationId,
				});
				this.detailInfo = mapPcDeclarationDetail(res, this.rowData);
				this.resetApproveForm();
			} catch (error) {
				console.error(error);
				this.detailInfo = null;
				this.$message.error("加载报备详情失败");
			} finally {
				this.loading = false;
			}
		},
		resetApproveForm() {
			this.approveForm = {
				auditResult: 1,
				auditRemark: "",
				extensionDeadline: getDefaultExtensionDate(3),
			};
			this.$nextTick(() => {
				if (this.$refs.approveFormRef) {
					this.$refs.approveFormRef.clearValidate();
				}
			});
		},
		handleClose() {
			this.drawerVisible = false;
			this.detailInfo = null;
		},
		handleSubmit() {
			this.$refs.approveFormRef.validate(async (valid) => {
				if (!valid) {
					return;
				}
				this.submitting = true;
				try {
					await approvePcAbnormalFlowDeclaration(
						mapApproveFormToApi(this.approveForm, this.rowData.declarationId),
					);
					this.$message.success("提交成功");
					this.$emit("success");
					this.handleClose();
				} catch (error) {
					console.error(error);
				} finally {
					this.submitting = false;
				}
			});
		},
	},
};
</script>

<style lang="scss" scoped>
::v-deep.abnormal-flow-drawer {
	.el-drawer__header {
		box-sizing: border-box;
		height: 60px;
		line-height: 60px;
		border-bottom: 1px solid #e5e5e5;
		padding: 0 0 0 20px;
		color: #333333;
		font-size: 20px;
		font-weight: bold;
		margin-bottom: 0;
	}
	.el-drawer__body {
		overflow: hidden;
		display: flex;
		flex-direction: column;
		height: calc(100% - 60px);
	}
}

.drawer-body {
	flex: 1;
	overflow-y: auto;
	padding: 0 0 70px;

	::v-deep .info-wrapper {
		margin: 0;
		.item .title {
			padding-left: 20px;
		}
	}
}

.section-block {
	margin-bottom: 20px;

	.section-title {
		color: #333333;
		font-size: 16px;
		font-weight: bold;
		padding: 13.5px 20px;
		border-bottom: 1px solid #e5e5e5;
		line-height: 23px;
	}

	.section-subtitle {
		color: #666666;
		font-size: 14px;
		padding: 8px 20px 0;
	}
}

.approve-form {
	padding: 20px 20px 0;

	.form-tip {
		color: #999999;
		font-size: 12px;
		line-height: 20px;
		margin-top: 4px;
	}
}

.drawer-footer {
	position: absolute;
	width: 100%;
	height: 60px;
	line-height: 60px;
	bottom: 0;
	right: 0;
	background: #ffffff;
	text-align: right;
	padding-right: 30px;
	border-top: 1px solid #e5e5e5;
	z-index: 9;
}
</style>