TableData.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="table">
  3. <uni-table border stripe emptyText="暂无更多数据">
  4. <!-- 表头行 -->
  5. <uni-tr>
  6. <uni-th align="center" width="50">序号</uni-th>
  7. <uni-th align="center">上级服务类型</uni-th>
  8. <uni-th align="center" width="50">积分值</uni-th>
  9. <uni-th align="center" width="50">任务总个数</uni-th>
  10. <uni-th align="center" width="50">已用个数</uni-th>
  11. <uni-th align="center" width="50">任务个数</uni-th>
  12. <uni-th align="center" width="80">任务积分值</uni-th>
  13. </uni-tr>
  14. <!-- 表格数据行 -->
  15. <uni-tr v-for="(item, index) in tableData" :key="item?.taskTypeId" index>
  16. <uni-td>{{ index + 1 }}</uni-td>
  17. <uni-td>{{ item.baseId }}</uni-td>
  18. <uni-td>{{ item.score }}</uni-td>
  19. <uni-td>{{ item.allQty }}</uni-td>
  20. <uni-td>{{ item.used }}</uni-td>
  21. <uni-td>
  22. <input type="number" @blur="(e) => change(e, index, item)" v-model="item.qty" />
  23. </uni-td>
  24. <uni-td>{{ item.subtotal }}</uni-td>
  25. </uni-tr>
  26. <!-- 结尾 -->
  27. <uni-tr>
  28. <uni-td>总计</uni-td>
  29. <uni-td>---</uni-td>
  30. <uni-td>---</uni-td>
  31. <uni-td>---</uni-td>
  32. <uni-td>---</uni-td>
  33. <uni-td>{{ totalQty }}</uni-td>
  34. <uni-td>{{ totalsubtotal }}</uni-td>
  35. </uni-tr>
  36. </uni-table>
  37. </view>
  38. </template>
  39. <script setup lang="ts">
  40. import { ref, defineEmits } from 'vue'
  41. const emit = defineEmits(['updateScope'])
  42. const tableData = ref<any[]>([])
  43. const totalQty = ref(0)
  44. const totalsubtotal = ref(0)
  45. const change = (detail: any, index: number, item: any) => {
  46. let max = item.allQty - item.used
  47. const value = tableData.value[index].qty
  48. if (value > max) {
  49. tableData.value[index].qty = max
  50. }
  51. tableData.value[index].subtotal = tableData.value[index].qty * tableData.value[index].score
  52. totalQty.value = tableData.value.reduce((sum, row) => Number(sum) + Number(row.qty), 0)
  53. totalsubtotal.value = tableData.value.reduce((sum, row) => Number(sum) + Number(row.subtotal), 0)
  54. emit('updateScope', totalsubtotal.value)
  55. }
  56. const setData = (data: any[]) => {
  57. tableData.value = [...data]
  58. tableData.value.forEach((item, index) => {
  59. item.index = index
  60. item.score = item.price
  61. item.subtotal = 0
  62. item.baseId = item.taskTypeName
  63. item.allQty = item.qty
  64. item.qty = 0
  65. })
  66. }
  67. const getData = () => {
  68. return tableData.value
  69. }
  70. defineExpose({ setData, getData })
  71. </script>
  72. <style lang="scss" scoped>
  73. .table {
  74. margin-top: 20rpx;
  75. width: 640rpx;
  76. min-height: 300rpx;
  77. background-color: #fff;
  78. border-radius: 12rpx;
  79. }
  80. </style>