refundDetail.vue 4.54 KB
<template>
    <el-dialog :before-close="handleClose"
               class="relateStore"
               :close-on-click-modal="false"
               title="请选择退款明细"
               :visible.sync="refundVisible"
               width="70%">
        <div>
            <el-table ref="seletingTable"
                      border
                      class="table"
                      :data="tableData"
                      @select="handleChange"
                      @select-all="handleAll">
                <el-table-column align="center"
                                 :selectable="selectableFn"
                                 type="selection"
                                 width="55" />
                <template v-for="item in tableColumn">
                    <el-table-column align="center"
                                     :label="item.label"
                                     :prop="item.prop">
                        <template #default="scope">
                            <span>
                                {{ scope.row[item.prop] ? item.unit ? item.unit + scope.row[item.prop] : scope.row[item.prop] : "-" }}
                            </span>
                        </template>
                    </el-table-column>
                </template>
            </el-table>
            <div class="total">
                可选可退总价:<div class="price">
                    ¥{{ total }}
                </div>
            </div>
        </div>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="handleClose">取 消</el-button>
                <el-button :disabled="!refundSubOrderCode"
                           type="primary"
                           @click="handleConfirm">
                    下一步
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script>
import { getGoodsSubOrder } from "@api/point";

export default {
	name: "RefundDetail",
	props: {
		refundVisible: {
			type: Boolean,
			default: false,
		},
		dataInfo: {
			type: Object,
			default: {},
		},
	},
	data() {
		return {
			tableData: [],
			tableColumn: [
				{
					label: "子订单编码",
					prop: "subOrderCode",
				},
				{
					label: "商品名称",
					prop: "goodsName",
				},
				{
					label: "商品别名",
					prop: "goodsAlias",
				},
				{
					label: "商品ID",
					prop: "goodsCommodityCode",
				},
				{
					label: "分类",
					prop: "upgradeGoodsTypeName",
				},
				{
					label: "售价",
					prop: "upgradePrice",
					unit: "¥",
				},
				{
					label: "数量/件",
					prop: "number",
				},
				{
					label: "支付金额",
					prop: "totalPrice",
					unit: "¥",
				},
			],
			total: 0,
			refundSubOrderCode: "",
			refundApplyDetailList: [],
			isAll: false,
			// 是否只有一个子订单并且未退过款的
			isOneSubFirst: false,
		};
	},
	watch: {
		dataInfo(val) {
			console.log(val);
			if (val && val.orderCode)
				this.getList(val.orderCode);
		},
	},
	methods: {
		// 设置禁用
		selectableFn(row) {
			console.log(row);
			if (row.status == 2)
				return false;
			else return true;
		},
		async getList(orderCode) {
			const res = await getGoodsSubOrder({ orderCode });
			this.tableData = res;
			this.isOneSubFirst = this.tableData.length == 1 && this.tableData.every(item => item.status == 1);
			this.$refs.seletingTable.toggleAllSelection();
		},
		handleChange(selection) {
			console.log(selection);
			this.isAll = selection.length == this.tableData.length;
			this.getParams(selection);
		},
		handleAll(selection) {
			console.log(selection);
			this.isAll = selection.length == this.tableData.length;
			this.getParams(selection);
		},
		getParams(selection) {
			let _total = 0;
			let _refundSubOrderCode = [];
			selection.forEach((item) => {
				_total += item.totalPrice;
				_refundSubOrderCode.push(item.subOrderCode);
			});
			this.total = Number.parseFloat(_total.toFixed(2));
			this.refundSubOrderCode = _refundSubOrderCode.join("/");
			this.refundApplyDetailList = selection;
			console.log(this.refundSubOrderCode);
		},
		handleConfirm() {
			const { refundSubOrderCode, refundApplyDetailList, total, isAll, isOneSubFirst } = this;
			this.$emit("handleConfirm", {
				total,
				refundSubOrderCode,
				isAll,
				refundApplyDetailList,
				isOneSubFirst,
			});
		},
		handleClose() {
			this.$emit("handleClose");
		},
	},
};
</script>

<style lang="scss" scoped>
.total {
	display: flex;
	align-items: center;
	color: #666666;
	font-size: 14px;
	.price {
		color: #2a58ad;
		margin-left: 10px;
	}
}
</style>