原生Table写一行保证两条数据

javascript 复制代码
<template>
    <el-dialog v-model="visible" width="80%" :show-close="false" :style="{ padding: 0, height: '70%' }">
        <template #title>
            <div class="section-header" style="background-color: #2b3a4a; padding: 10px; color: white;">
                {{ t('user_recom.会员分成设置') }}
            </div>
        </template>

        <!-- 表格 -->
        <table class="order_write order_table_top">
            <colgroup>
                <col width="12%" />
                <col />
                <col width="12%" />
                <col />
            </colgroup>

            <tbody>
                <tr v-for="(row, index) in tableRows" :key="index">
                    <!-- 左 -->
                    <th class="parrent_menu">
                        <el-checkbox v-if="row[0]" v-model="row[0].isChecked" />
                    </th>
                    <td>
                        <template v-if="row[0]">
                            {{ row[0].type }} →
                            {{ row[0].surcharge_name }}
                        </template>
                    </td>

                    <!-- 右 -->
                    <th class="parrent_menu">
                        <el-checkbox v-if="row[1]" v-model="row[1].isChecked" />
                    </th>
                    <td>
                        <template v-if="row[1]">
                            {{ row[1].type }} →
                            {{ row[1].surcharge_name }}
                        </template>
                    </td>
                </tr>
            </tbody>
        </table>
        <table class="order_write order_table_top">
            <colgroup>
                <col width="12%" />
                <col />
                <col width="12%" />
                <col />
            </colgroup>

            <tbody>
                <tr v-for="(row, index) in tableRows" :key="index">
                    <!-- 左 -->
                    <th class="parrent_menu">
                        <el-checkbox v-if="row[0]" v-model="row[0].isChecked" />
                    </th>
                    <td>
                        <template v-if="row[0]">
                            {{ row[0].type }} →
                            {{ row[0].surcharge_name }}
                        </template>
                    </td>

                    <!-- 右 -->
                    <th class="parrent_menu">
                        <el-checkbox v-if="row[1]" v-model="row[1].isChecked" />
                    </th>
                    <td>
                        <template v-if="row[1]">
                            {{ row[1].type }} →
                            {{ row[1].surcharge_name }}
                        </template>
                    </td>
                </tr>
            </tbody>
        </table>


        <!-- 弹窗底部 -->
        <template #footer>
            <div class="footer-btn">
                <el-button type="primary" @click="handleSave" :disabled="saveLoading">{{ t('btn.enter') }}</el-button>
                <el-button type="primary" plain @click="visible = false">
                    {{ t('btn.close') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup>
import { ref, computed, reactive } from 'vue'
import { useI18n } from 'vue-i18n'
import { toast } from '~/composables/util'
import { formatAmount } from '~/composables/validate'
import { recomdService } from '~/api/user'
const { t } = useI18n()
const visible = ref(false)
const tableList = ref([])
const saveLoading = ref(false)

const tableRows = computed(() => {
    const rows = []
    for (let i = 0; i < tableList.value.length; i += 2) {
        rows.push([
            tableList.value[i],
            tableList.value[i + 1] || null
        ])
    }
    return rows
})


const getSettingList = async () => {
    const res = await recomdService.getCommissionInit()
    if (res.code === 200) {
        let resData = res.data
        if (resData.length > 0) {
            tableList.value = resData.map(item => {
                return {
                    ...item,
                    isChecked: Boolean(item.isChecked)
                }
            })
        }

    } else {
        tableList.value = []
        setTimeout(() => {
            toast(res.msg, 'error')
            visible.value = false
        }, 2000)
    }

}


const handleSave = async () => {
    const checkedCodes = tableList.value
        .filter(item => item.isChecked)
        .map(item => item.surcharge_code)

    if (!checkedCodes.length) {
        toast(t('sys.choose-one-item'), 'warning')
        return
    }

    saveLoading.value = true
    try {
        const res = await recomdService.setMemberCommission({
            : checkedCodes
        })
        if (res.code === 200) {
            visible.value = false
        }
    } finally {
        saveLoading.value = false
    }
}




const open = () => {
    visible.value = true
    getSettingList()
}

defineExpose({ open })


</script>

<style scoped>
.select-box {
    width: 150px;
    margin-right: 3px;
}

.search-input {
    width: 120px;
    margin-right: 3px;
}

.main-table {
    margin-top: 10px;
    max-height: 480px;
    overflow-y: auto;
}


.charge-wrap {
    display: flex;
    flex-wrap: wrap;
}

.charge-item {
    width: 30%;
    margin-right: 1px;
    white-space: nowrap;
}
</style>
相关推荐
程序员清洒1 小时前
Flutter for OpenHarmony:Text — 文本显示与样式控制
开发语言·javascript·flutter
雨季6662 小时前
Flutter 三端应用实战:OpenHarmony 简易“动态内边距调节器”交互模式深度解析
javascript·flutter·ui·交互·dart
会飞的战斗鸡2 小时前
JS中的链表(含leetcode例题)
javascript·leetcode·链表
方也_arkling3 小时前
别名路径联想提示。@/统一文件路径的配置
前端·javascript
qq_177767373 小时前
React Native鸿蒙跨平台剧集管理应用实现,包含主应用组件、剧集列表、分类筛选、搜索排序等功能模块
javascript·react native·react.js·交互·harmonyos
qq_177767373 小时前
React Native鸿蒙跨平台自定义复选框组件,通过样式数组实现选中/未选中状态的样式切换,使用链式调用替代样式数组,实现状态驱动的样式变化
javascript·react native·react.js·架构·ecmascript·harmonyos·媒体
web打印社区3 小时前
web-print-pdf:突破浏览器限制,实现专业级Web静默打印
前端·javascript·vue.js·electron·html
烬头88214 小时前
React Native鸿蒙跨平台采用了函数式组件的形式,通过 props 接收分类数据,使用 TouchableOpacity实现了点击交互效果
javascript·react native·react.js·ecmascript·交互·harmonyos
Amumu121384 小时前
Vuex介绍
前端·javascript·vue.js
2601_949809594 小时前
flutter_for_openharmony家庭相册app实战+相册详情实现
javascript·flutter·ajax