viewer.vue 10.5 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
<template>
	<view class="page">
		<!-- 基础信息 -->
		<view class="section">
			<view class="company-row">
				<text class="company">{{ form.companyShortName || '-' }}</text>
				<text v-if="requestKindName" class="kind-tag">{{ requestKindName }}</text>
			</view>
			<view class="row"><text class="label">分厂</text><text class="value">{{ form.workshopName || '-' }}</text></view>
			<view class="row"><text class="label">计划编号</text><text class="value">{{ formatPlanCodes(form.planCodes) || '-' }}</text></view>
			<view class="row"><text class="label">日期</text><text class="value">{{ form.requestDate || '-' }}</text></view>
			<view class="row"><text class="label">付款方式</text><text class="value">{{ bizTypeName || '-' }}</text></view>
			<view class="row"><text class="label">对方户名</text><text class="value">{{ form.payeeName || '-' }}</text></view>
			<view class="row"><text class="label">开户银行</text><text class="value">{{ form.bankName || '-' }}</text></view>
			<view class="row"><text class="label">账号</text><text class="value">{{ form.bankAccount || '-' }}</text></view>
		</view>

		<!-- 请款明细 -->
		<view class="sub-table">
			<view class="sub-header">
				<image class="sub-bar" src="/static/images/title.png" />
				<text class="sub-title">请款明细</text>
			</view>
			<view class="sub-body">
				<view v-if="!lines.length" class="empty-tip">暂无明细</view>
				<view v-for="(item, idx) in lines" :key="idx" class="card">
					<view class="card-index">第 {{ idx + 1 }} 行</view>
					<view class="row"><text class="label">计划编号</text><text class="value">{{ item.planCode || '-' }}</text></view>
					<view class="row"><text class="label">预付金额</text><text class="value">{{ formatAmount(item.prepaidAmount) }}</text></view>
					<view class="row"><text class="label">申请金额</text><text class="value">{{ formatAmount(item.applyAmount) }}</text></view>
				</view>
				<view class="total-row">
					<text class="total-title">合计金额</text>
					<view class="total-item">
						<text class="total-label">预付金额</text>
						<text class="total-value">{{ formatAmount(form.totalPrepayAmount) }}</text>
					</view>
					<view class="total-item">
						<text class="total-label">申请金额</text>
						<text class="total-value">{{ formatAmount(form.totalApplyAmount) }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 补充信息 -->
		<view class="title-header">
			<image class="title-header_icon" src="/static/images/title.png" />
			<span>补充信息</span>
		</view>
		<view class="section">
			<view class="row"><text class="label">请款说明</text><text class="value">{{ form.requestRemark || '-' }}</text></view>
			<view v-if="form.requestKind === 'SUPPLEMENT'" class="row">
				<text class="label">补充说明</text><text class="value">{{ form.supplementRemark || '-' }}</text>
			</view>
			<view v-if="form.requestKind === 'SUPPLEMENT' && supplementFileList.length" class="row">
				<text class="label">补充说明附件</text>
				<view class="value">
					<view v-for="(item, i) in supplementFileList" :key="item.fileId || i" class="file-item"
						@click="downloadAttachment(item)">
						<text class="value act">{{ item.fileName }}</text>
					</view>
				</view>
			</view>
			<view v-if="attachmentFileList.length" class="row">
				<text class="label">请款附件</text>
				<view class="value">
					<view v-for="(item, i) in attachmentFileList" :key="item.fileId || i" class="file-item"
						@click="downloadAttachment(item)">
						<text class="value act">{{ item.fileName }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { getDetailApi } from '@/api/payment-request.js'
import { getDicByCodes, getDicName } from '@/utils/dic.js'
import { downloadFile } from '@/utils/downloadFile.js'

export default {
	name: 'PaymentRequestViewer',
	props: { id: { type: [String, Number], default: '' } },
	data() {
		return {
			form: {},
			lines: [],
			dicOptions: {
				DELIVERY_METHOD: [],
				REQUEST_KIND: []
			}
		}
	},
	computed: {
		// 付款方式名称(code 转名称)
		bizTypeName() {
			const v = (this.form && this.form.bizType) || ''
			if (!v) return ''
			return getDicName('DELIVERY_METHOD', v, this.dicOptions.DELIVERY_METHOD) || v
		},
		// 请款单类型名称
		requestKindName() {
			const v = (this.form && this.form.requestKind) || ''
			if (!v) return ''
			return getDicName('REQUEST_KIND', v, this.dicOptions.REQUEST_KIND) || ''
		},
		// 请款附件列表(多文件逗号分隔解析)
		attachmentFileList() {
			return this.parseAttachmentList(
				(this.form && this.form.requestFileIds) || (this.form && this.form.attachmentFileIds) || '',
				(this.form && this.form.requestFileName) || (this.form && this.form.attachmentFileNames) || ''
			)
		},
		// 补充说明附件列表
		supplementFileList() {
			return this.parseAttachmentList(
				(this.form && this.form.supplementFileIds) || '',
				(this.form && this.form.supplementFileNames) || ''
			)
		},
	},
	created() {
		this.loadDicData()
	},
	watch: {
		id: {
			immediate: true,
			handler(val) {
				const v = (val !== undefined && val !== null) ? String(val) : ''
				if (v) this.loadDetail(v)
			}
		}
	},
	methods: {
		async loadDicData() {
			try {
				const results = await getDicByCodes(['DELIVERY_METHOD', 'REQUEST_KIND'])
				this.dicOptions.DELIVERY_METHOD = (results.DELIVERY_METHOD && results.DELIVERY_METHOD.data) || []
				this.dicOptions.REQUEST_KIND = (results.REQUEST_KIND && results.REQUEST_KIND.data) || []
			} catch (e) {
				this.dicOptions = { DELIVERY_METHOD: [], REQUEST_KIND: [] }
			}
		},
		// 按业务 id 加载请款单详情
		async loadDetail(id) {
			try {
				const res = await getDetailApi(id)
				const m = (res && res.data) || {}
				this.form = m
				this.lines = Array.isArray(m.lines) ? m.lines : []
			} catch (e) {
				this.form = {}
				this.lines = []
			}
		},
		// 附件字段(多文件逗号分隔)解析为文件列表
		parseAttachmentList(idsStr, namesStr) {
			const ids = String(idsStr || '').split(',').map(x => x.trim()).filter(Boolean)
			const names = String(namesStr || '').split(',').map(x => x.trim())
			return ids.map((id, idx) => ({
				fileId: id,
				fileName: names[idx] || `附件${idx + 1}`
			}))
		},
		downloadAttachment(item) {
			const id = (item && item.fileId) || ''
			const fileName = (item && item.fileName) || ''
			if (!id) return
			downloadFile(id, fileName)
		},
		// 计划编号格式化(接口返回数组,转为逗号分隔文本)
		formatPlanCodes(v) {
			if (v === null || v === undefined || v === '') return ''
			if (Array.isArray(v)) return v.filter(Boolean).join(',')
			return String(v)
		},
		formatAmount(v) {
			if (v === null || v === undefined || v === '') return '-'
			const n = Number(v)
			if (isNaN(n)) return String(v)
			return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
		},
		// 供 BPM 审批通过时取业务表单数据(variables)
		getFormValues() {
			const m = this.form || {}
			return JSON.parse(JSON.stringify(m))
		},
		// 供 BPM 审批通过前的校验钩子(请款单审批表单只读,无需校验)
		checkForm() {
			return true
		}
	}
}
</script>

<style lang="scss" scoped>
.page {
	padding-bottom: 20rpx;
	background: #f3f3f3;
}

.section {
	padding: 32rpx;
	background: #fff;
	margin-bottom: 20rpx;
	position: relative;
}

.company-row {
	display: flex;
	align-items: center;
	margin-bottom: 32rpx;

	.company {
		font-size: 36rpx;
		font-weight: 600;
		color: rgba(0, 0, 0, 0.9);
		padding-top: 10rpx;
		line-height: 50rpx;
	}

	.kind-tag {
		flex-shrink: 0;
		margin-left: 16rpx;
		margin-top: 10rpx;
		padding: 4rpx 12rpx;
		border-radius: 6rpx;
		font-size: 22rpx;
		line-height: 32rpx;
		background: #FFF1E9;
		color: #E37318;
	}
}

.row {
	display: flex;
	margin-bottom: 28rpx;

	&:last-child {
		margin-bottom: 0;
	}

	.label {
		max-width: 420rpx;
		margin-right: 20rpx;
		line-height: 32rpx;
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.6);
	}

	.value {
		flex: 1;
		line-height: 32rpx;
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.9);
		text-align: right;
		word-break: break-all;

		&.act {
			color: $theme-primary;
		}
	}

	.file-item {
		margin-bottom: 12rpx;

		&:last-child {
			margin-bottom: 0;
		}
	}
}

.title-header {
	display: flex;
	align-items: center;
	padding: 24rpx 32rpx 12rpx;
	background-color: #ffffff;

	.title-header_icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 12rpx;
	}

	span {
		font-size: 34rpx;
		font-weight: 600;
		color: rgba(0, 0, 0, 0.9);
	}
}

.sub-table {
	background: #fff;
	margin-bottom: 20rpx;
}

.sub-header {
	display: flex;
	align-items: center;
	padding: 16rpx 0 16rpx 32rpx;

	.sub-bar {
		width: 6rpx;
		height: 32rpx;
		margin-right: 14rpx;
	}

	.sub-title {
		font-size: 30rpx;
		font-weight: 600;
		color: rgba(0, 0, 0, 0.9);
		flex: 1;
		line-height: 42rpx;
	}
}

.sub-body {
	padding: 0 32rpx 24rpx;

	.empty-tip {
		text-align: center;
		padding: 60rpx 0;
		color: rgba(0, 0, 0, 0.4);
		font-size: 28rpx;
	}

	.card {
		position: relative;
		background: #fafafa;
		border-radius: 12rpx;
		padding: 32rpx 28rpx 20rpx;
		margin-bottom: 24rpx;

		.card-index {
			position: absolute;
			top: 0;
			right: 0;
			background: rgba(24, 144, 255, 0.08);
			color: $theme-primary;
			font-size: 22rpx;
			line-height: 36rpx;
			padding: 0 16rpx;
			border-bottom-left-radius: 12rpx;
			border-top-right-radius: 12rpx;
		}

		.row {
			align-items: center;
			justify-content: space-between;
			padding: 14rpx 0;
			margin-bottom: 0;
			border-bottom: 1rpx dashed #f2f2f2;

			&:last-child {
				border-bottom: none;
			}

			.label {
				flex-shrink: 0;
				width: 220rpx;
				max-width: none;
				margin-right: 0;
				font-size: 28rpx;
				color: rgba(0, 0, 0, 0.6);
				line-height: 40rpx;
			}

			.value {
				flex: 1;
				text-align: right;
				font-size: 28rpx;
				color: rgba(0, 0, 0, 0.9);
				line-height: 40rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
		}
	}

	.total-row {
		display: flex;
		align-items: center;
		padding: 20rpx 28rpx;
		border-radius: 12rpx;
		border: 1rpx solid #e5e6eb;
		background: #fafafa;

		.total-title {
			flex-shrink: 0;
			font-size: 28rpx;
			font-weight: 600;
			color: rgba(0, 0, 0, 0.9);
			margin-right: 32rpx;
		}

		.total-item {
			display: flex;
			align-items: center;
			margin-right: 32rpx;

			&:last-child {
				margin-right: 0;
			}

			.total-label {
				font-size: 26rpx;
				color: rgba(0, 0, 0, 0.6);
				margin-right: 8rpx;
			}

			.total-value {
				font-size: 26rpx;
				color: rgba(0, 0, 0, 0.9);
			}
		}
	}
}
</style>