调整table组件
This commit is contained in:
@@ -4,36 +4,23 @@
|
|||||||
<view class="u-flex u-row-between no-wrap title">
|
<view class="u-flex u-row-between no-wrap title">
|
||||||
<!-- 全选框 -->
|
<!-- 全选框 -->
|
||||||
<view class="table-th">
|
<view class="table-th">
|
||||||
<my-radio
|
<up-checkbox @change="handleSelectAll" usedAlone v-model:checked="internalAllChecked" shape="square" :size="20" />
|
||||||
@change="handleSelectAll"
|
|
||||||
v-model="internalAllChecked"
|
|
||||||
shape="square"
|
|
||||||
:size="20"
|
|
||||||
/>
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 动态列标题 -->
|
<!-- 动态列标题 -->
|
||||||
<view class="table-th" v-for="col in columns" :key="col.key" :style="col.style || {}">
|
<view class="table-th" v-for="col in columns" :key="col.key" :style="col.style || {}">
|
||||||
{{ col.label }}
|
{{ col.title }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 表格行 -->
|
<!-- 表格行 -->
|
||||||
<view
|
<view @click="handleRowCheck(item)" class="u-m-t-12 u-flex u-p-24 u-row-between row"
|
||||||
@click="handleRowCheck(item)"
|
v-for="(item, index) in internalData" :key="item.id || index" row-key="id">
|
||||||
class="u-m-t-12 u-flex u-p-24 u-row-between row"
|
|
||||||
v-for="(item, index) in internalData"
|
|
||||||
:key="item.id || index"
|
|
||||||
row-key="id"
|
|
||||||
>
|
|
||||||
<!-- 单选框 -->
|
<!-- 单选框 -->
|
||||||
<view class="table-td">
|
<view class="table-td">
|
||||||
<my-radio
|
<up-checkbox
|
||||||
v-model="item._checked"
|
usedAlone
|
||||||
shape="square"
|
v-model:checked="item._checked" shape="square" :size="20" @change="handleRowCheck(item)"></up-checkbox>
|
||||||
:size="20"
|
|
||||||
@change="handleRowCheck(item)"
|
|
||||||
/>
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 动态列内容 -->
|
<!-- 动态列内容 -->
|
||||||
@@ -49,7 +36,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, watch } from 'vue';
|
import {
|
||||||
|
ref,
|
||||||
|
computed,
|
||||||
|
watch
|
||||||
|
} from 'vue';
|
||||||
|
|
||||||
// 完全对齐 u-table2 的 props
|
// 完全对齐 u-table2 的 props
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -84,16 +75,20 @@ watch(
|
|||||||
...item,
|
...item,
|
||||||
_checked: item._checked || false
|
_checked: item._checked || false
|
||||||
}));
|
}));
|
||||||
},
|
}, {
|
||||||
{ immediate: true, deep: true }
|
immediate: true,
|
||||||
|
deep: true
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// 全选切换
|
// 全选切换
|
||||||
function handleSelectAll() {
|
function handleSelectAll() {
|
||||||
const checked = internalAllChecked.value;
|
const checked = internalAllChecked.value;
|
||||||
internalData.value.forEach(item => {
|
internalData.value=internalData.value.map(item=>{
|
||||||
item._checked = checked;
|
item._checked = checked;
|
||||||
});
|
return item;
|
||||||
|
})
|
||||||
|
console.log('internalData.value',internalData.value);
|
||||||
emitChange();
|
emitChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,8 +111,9 @@ watch(
|
|||||||
const total = internalData.value.length;
|
const total = internalData.value.length;
|
||||||
const checkedCount = internalData.value.filter(i => i._checked).length;
|
const checkedCount = internalData.value.filter(i => i._checked).length;
|
||||||
internalAllChecked.value = total > 0 && checkedCount === total;
|
internalAllChecked.value = total > 0 && checkedCount === total;
|
||||||
},
|
}, {
|
||||||
{ deep: true }
|
deep: true
|
||||||
|
}
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,21 @@
|
|||||||
let $goodsMap = {}
|
let $goodsMap = {}
|
||||||
let goosZhonglei = ref(0)
|
let goosZhonglei = ref(0)
|
||||||
let goodsNumber = ref(0)
|
let goodsNumber = ref(0)
|
||||||
let originAmount = ref(0)
|
let originAmount = computed(()=>{
|
||||||
|
let total=0;
|
||||||
|
for (let i in props.data.goods) {
|
||||||
|
const goods = props.data.goods[i]
|
||||||
|
if ($goodsMap.hasOwnProperty(goods.productId)) {
|
||||||
|
$goodsMap[goods.productId] += goods.num * 1
|
||||||
|
goodsNumber.value += goods.num * 1
|
||||||
|
} else {
|
||||||
|
$goodsMap[goods.productId] = goods.num * 1
|
||||||
|
goosZhonglei.value += 1
|
||||||
|
}
|
||||||
|
total += goods.payAmount
|
||||||
|
}
|
||||||
|
return total
|
||||||
|
})
|
||||||
const priceSize = 9
|
const priceSize = 9
|
||||||
let minWidth=ref(36)
|
let minWidth=ref(36)
|
||||||
|
|
||||||
@@ -138,17 +152,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function goodsMapInit() {
|
function goodsMapInit() {
|
||||||
for (let i in props.data.goods) {
|
|
||||||
const goods = props.data.goods[i]
|
|
||||||
if ($goodsMap.hasOwnProperty(goods.productId)) {
|
|
||||||
$goodsMap[goods.productId] += goods.num * 1
|
|
||||||
goodsNumber.value += goods.num * 1
|
|
||||||
} else {
|
|
||||||
$goodsMap[goods.productId] = goods.num * 1
|
|
||||||
goosZhonglei.value += 1
|
|
||||||
}
|
|
||||||
originAmount.value += goods.payAmount
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
goodsMapInit()
|
goodsMapInit()
|
||||||
watch(() => props.data.goods.length, (newval) => {
|
watch(() => props.data.goods.length, (newval) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user