vue+js实现动态计算勾选顺序,并且指定不同分组不同计算逻辑

首先是效果图
在这里插入图片描述
在这里插入图片描述
vue代码

<el-table :data="atlasDataList" style="width: 100%" :span-method="spanMethod" border>
              <el-table-column prop="stationName" label="" width="180" />
              <el-table-column prop="atlasNumber" label="" width="180" />
              <el-table-column label="图册名称" width="180">
                <template #default="{ row }">
                  <el-checkbox v-model="row.checked" :label="row.atlasName" @change="handleCheckboxChange(row)" />
                </template>
              </el-table-column>
              <el-table-column prop="atlasFigureNumber" label="图号(图册)" width="180">
                <template #default="{ row }">
                  <span v-if="row.checked">{{row.atlasNumber + '-' + row.atlasFigureNumber}}</span>
                  <span v-else></span>
                </template>
              </el-table-column>
            </el-table>

js代码(合并行的方法见上一篇文章)

<script setup>

const atlasDataList = ref(
[
    {
        "stationName": "车站1",
        "atlasNumber": "大瑞施号1",
        "atlasName": "计算机联锁图册",
        "checked": true,
        "atlasFigureNumber": "Ⅰ"
    },
    {
        "stationName": "车站1",
        "atlasNumber": "大瑞施号1",
        "atlasName": "区间自动闭塞图册",
        "checked": true,
        "atlasFigureNumber": "Ⅱ"
    },
    {
        "stationName": "车站1",
        "atlasNumber": "大瑞施号1",
        "atlasName": "信号集中监测图册"
    },
    {
        "stationName": "车站1",
        "atlasNumber": "大瑞施号1",
        "atlasName": "列车运行控制系统图册",
        "checked": true,
        "atlasFigureNumber": "Ⅲ"
    },
    {
        "stationName": "车站2",
        "atlasNumber": "大瑞施号2",
        "atlasName": "计算机联锁图册",
        "checked": true,
        "atlasFigureNumber": "Ⅰ"
    },
    {
        "stationName": "车站2",
        "atlasNumber": "大瑞施号2",
        "atlasName": "区间自动闭塞图册"
    },
    {
        "stationName": "车站2",
        "atlasNumber": "大瑞施号2",
        "atlasName": "信号集中监测图册",
        "checked": false,
        "atlasFigureNumber": "Ⅱ"
    },
    {
        "stationName": "车站2",
        "atlasNumber": "大瑞施号2",
        "atlasName": "列车运行控制系统图册",
        "checked": true,
        "atlasFigureNumber": "Ⅱ"
    }
]);
  
  //选中图册名称的方法
    function handleCheckboxChange(row) {
      // 获取当前行的位置索引
      const rowIndex = atlasDataList.value.indexOf(row);

      // 计算当前行所在的分组索引
      const groupIndex = Math.floor(rowIndex / atlasTypeList.value.length);

      // 获取当前分组的所有行
      const groupRows = atlasDataList.value.slice(groupIndex * atlasTypeList.value.length, (groupIndex + 1) * atlasTypeList.value.length);

      // 获取当前分组内勾选的行
      const checkedGroupRows = groupRows.filter(item => item.checked);

      // 遍历勾选的行,设置图号(图册)属性
      checkedGroupRows.forEach((checkedRow, index) => {
        checkedRow.atlasFigureNumber = convertToRomanNumeral(index + 1);
      });
    }

    //将数字转换为罗马数字
    function convertToRomanNumeral(number) {
      const romanNumerals = [
        { value: 10, numeral: 'Ⅹ' },
        { value: 9, numeral: 'Ⅸ' },
        { value: 8, numeral: 'Ⅷ' },
        { value: 7, numeral: 'Ⅶ' },
        { value: 6, numeral: 'Ⅵ' },
        { value: 5, numeral: 'Ⅴ' },
        { value: 4, numeral: 'Ⅳ' },
        { value: 3, numeral: 'Ⅲ' },
        { value: 2, numeral: 'Ⅱ' },
        { value: 1, numeral: 'Ⅰ' }
      ];

      let result = '';
      for (const numeral of romanNumerals) {
        while (number >= numeral.value) {
          result += numeral.numeral;
          number -= numeral.value;
        }
      }
      return result;
    }
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值