RecordTransfer.vue 8.58 KB
<template>
  <d2-dialog btn-ok-label="关闭"
             class="privacyDailog"
             no-cancel="true"
             title="转账记录"
             width="1080px"
             :is-visible="recordTransferVisible"
             @closeDialog="handleClose"
             @confirmDialog="handleConfirm">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane v-for="(item, index) in tabPaneList"
                   :key="index"
                   :label="item.label"
                   :name="item.name">
      </el-tab-pane>
    </el-tabs>
    <glsx-combi-form ref="editFormRef"
                     class="edit-form-container"
                     default-width="314px"
                     label-width="250px"
                     :form-data="editFormData"
                     :form-obj="editData"
                     :form-ref="editChildRef"
                     :form-rules="formRules"
                     :is-block="isBlock">
      <div slot="fileHtml"
           slot-scope="scope"
           class="file-box">
        <div v-for="(subItem, subIndex) in editData.fileUrlList" :key="subIndex">
          <div class="file-item">
            <div class="file-content">
              <div class="file-name">
                {{ subItem.split('/')[subItem.split('/').length - 1] }}
              </div>
              <a href="#"
                 style="padding-left: 8px; color: #185efe"
                 @click="download(subItem)">
                下载
              </a>
            </div>
          </div>
        </div>
      </div>
      <template slot="expenseCategoryHtml">
        <div class="expense-category-text">
          <span v-for="item in editData.expenseCategoryList"
                :key="item.expenseCategoryId"
                class="expense-category-item">
            {{ getCategoryTxt(item) }}
          </span>
        </div>
      </template>
      <template slot="invoiceRemarkHtml">
        <div class="record-transfer-text">
          {{ editData.invoiceRemark }}
        </div>
      </template>
    </glsx-combi-form>
    <div>操作日志</div>
    <d2-table ref="logTable"
              :array-span-method="arraySpanMethod"
              :has-num="false"
              :has-page="false"
              :selectable-fn="selectableFn"
              :table-data="logList"
              :table-params="tableParams">
    </d2-table>
  </d2-dialog>
</template>

<script>
import { getTransferRecord } from "@api/accountManage";
import { deepClone, downLoadFile, Util } from "@/common/util";
import {
	EXPENSE_CATEGORY_OPTIONS,
} from "../accountStateManage/marketTransfer";

export default {
	name: "RecordTransfer",

	props: {
		recordTransferVisible: {
			type: Boolean,
			default: false,
		},
		info: {
			type: Object,
			default: () => ({}),
		},
	},
	data() {
		return {
			activeName: "0",
			tabPaneList: [],
			transferList: [],
			isBlock: true,
			editChildRef: "editChildRef",
			formRules: {
				amount: [{ required: true, message: "请输入转账金额", trigger: "change" }],
				fileUrlList: [{ required: true, message: "请选择转账凭证", trigger: "change" }],
				remark: [{ required: true, message: "请输入备注", trigger: "change" }],
			},
			editData: {
				platformMerchantId: "",
				platformMerchantName: "",
			},
			baseEditFormData: [
				{
					label: "所属平台方",
					name: "platformMerchantName",
					type: "showTxt",
				},
				{
					label: "对账服务商",
					name: "billMerchantName",
					type: "showTxt",
				},
				{
					label: "转账金额",
					name: "amount",
					type: "showTxt",
				},
				{
					label: "转账凭证",
					name: "fileUrlList",
					addHtml: "fileHtml",
				},
				{
					label: "备注",
					name: "remark",
					type: "showTxt",
				},
				{
					label: "企微审批状态",
					name: "oaApproveStatusTxt",
					type: "showTxt",
				},
				{
					label: "企微审批号",
					name: "oaSpNo",
					type: "showTxt",
				},
			],
			logList: [],
			tableParams: {
				btnId: new Date().getTime() + Number.parseInt(Math.random() * 1000),
				listName: "list",
				tableOption: false,
				tableColumns: [
					{
						label: "操作项",
						prop: "oprType",
						formatter: (cellValue) => {
							return { 1: "新增应付转账", 2: "推送企微OA", 3: "新增市场费转账" }[cellValue.oprType] || "";
						},
					},
					{
						label: "操作时间",
						prop: "createdDate",
					},
					{
						label: "操作结果",
						prop: "remark",
					},
					{
						label: "操作人",
						prop: "createdBy",
					},
				],
			},
		};
	},

	computed: {
		editFormData() {
			return this.buildEditFormData(this.editData);
		},
	},

	mounted() {
		this.editData = deepClone(this.info);
		this.getTransferRecord();
	},

	methods: {
		isMarketTransferRecord(record = {}) {
			return Array.isArray(record.expenseCategoryList);
		},
		getBillMerchantLabel(record = {}) {
			if (!this.isMarketTransferRecord(record))
				return "对账服务商";
			return record.billType == "1" ? "所属流量方" : "所属服务商";
		},
		buildEditFormData(record = {}) {
			const formData = deepClone(this.baseEditFormData);
			const billMerchant = formData.find(item => item.name === "billMerchantName");
			if (billMerchant)
				billMerchant.label = this.getBillMerchantLabel(record);
			if (!this.isMarketTransferRecord(record))
				return formData;

			const amountIndex = formData.findIndex(item => item.name === "amount");
			const expenseFields = [
				{
					label: "费用类型",
					name: "expenseCategoryList",
					addHtml: "expenseCategoryHtml",
				},
				...(record.expenseCategoryList || []).map(item => ({
					label: EXPENSE_CATEGORY_OPTIONS.find(i => i.id == item.expenseCategoryId).label + "金额",
					name: `expenseAmount_${item.expenseCategoryId}`,
					type: "showTxt",
					formatter: row => row[`expenseAmount_${item.expenseCategoryId}`] ?? "",
				})),
				{
					label: "收款账户",
					name: "rcvBankName",
					type: "showTxt",
					formatter: row => row.rcvName + " / " + row.rcvAcc,
				},
			];
			formData.splice(amountIndex, 0, ...expenseFields);

			const fileIndex = formData.findIndex(item => item.name === "fileUrlList");
			formData.splice(fileIndex, 0, {
				label: "发票及其他说明",
				name: "invoiceRemark",
				addHtml: "invoiceRemarkHtml",
			});
			return formData;
		},
		normalizeTransferRecord(item = {}) {
			const record = {
				...item,
				fileUrlList: item.fileUrl ? item.fileUrl.split(",").filter(Boolean) : [],
				rcvBankName: item.rcvBankName,
			};
			if (this.isMarketTransferRecord(record)) {
				record.expenseCategoryList = record.expenseCategoryList || [];
				record.expenseCategoryList.forEach((expense) => {
					record[`expenseAmount_${expense.expenseCategoryId}`] = expense.expenseCategoryResult;
				});
				if ((record.amount === undefined || record.amount === null || record.amount === "") && record.transferTotalAmount !== undefined) {
					record.amount = record.transferTotalAmount;
				}
			}
			return record;
		},
		getTransferRecord() {
			getTransferRecord({ id: this.info.id }).then((res) => {
				this.transferList = (res.transferList || []).map(item => this.normalizeTransferRecord(item));
				this.dealTabList();
				this.editData = deepClone(this.transferList[0]) || {};
				console.log(this.editData, "this.editData");
				this.logList = this.editData.logList || [];
			});
		},
		getCategoryTxt(item) {
			return EXPENSE_CATEGORY_OPTIONS.find(i => i.id == item.expenseCategoryId)?.label || item.expenseCategoryName;
		},
		dealTabList() {
			const statusObj = {
				1: "审批中",
				2: "已通过",
				3: "已驳回",
				4: "已撤销",
			};
			this.transferList.forEach((item, idx) => {
				this.transferList[idx].oaApproveStatusTxt = statusObj[item.oaApproveStatus] || "";
				this.tabPaneList.push({
					label: "转账记录" + (idx + 1),
					name: idx + "",
				});
			});
		},
		download(item) {
			downLoadFile(item);
		},
		handleClick(tab, event) {
			this.editData = deepClone(this.transferList[+tab.name]) || {};
			this.logList = this.editData.logList || [];
		},
		handleConfirm() {
			this.$emit("dialogClose");
		},
		handleClose() {
			this.$emit("dialogClose");
		},
	},
};
</script>

<style lang="scss" scoped>
.privacyDailog .el-dialog {
	min-width: 700px;
}
.file-content {
	display: flex;
	align-items: center;
	margin-bottom: 8px;
}
.expense-category-text {
	display: inline-flex;
	flex-wrap: wrap;
	width: 314px;
	line-height: 32px;
	vertical-align: top;
}
.expense-category-item {
	margin-right: 16px;
	color: #333;
}
.record-transfer-text {
	display: inline-block;
	width: 616px;
	margin-top: 6px;
	line-height: 22px;
	color: #333;
	vertical-align: top;
	white-space: normal;
	word-break: break-all;
}
</style>