ProductTable.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!--
  2. * @Author: liuzhenlin 461480418@qq.ocm
  3. * @Date: 2023-01-05 17:43:46
  4. * @LastEditors: liuzhenlin
  5. * @LastEditTime: 2023-01-07 14:36:08
  6. * @FilePath: \订单全流程管理系统\src\components\table\ProductTable.vue
  7. -->
  8. <template>
  9. <div class="table-container">
  10. <el-table border :data="data">
  11. <el-table-column
  12. v-for="(item, index) in columns"
  13. :key="index"
  14. align="center"
  15. :label="item.label"
  16. :min-width="item.width"
  17. :prop="item.prop"
  18. show-overflow-tooltip>
  19. <template #default="{ row }">
  20. <span v-if="item.prop == 'prodPrice'">
  21. <amount-input
  22. v-model.trim="row.prodPrice"
  23. placeholder="请输入金额"
  24. :value="row.prodPrice"
  25. @change="handleChange(row)" />
  26. </span>
  27. <span v-else-if="item.prop == 'prodNum'">
  28. <el-input-number v-model="row.prodNum" :min="0" size="mini" @change="handleChange(row)" />
  29. </span>
  30. <span v-else-if="item.label == '合计'">
  31. {{ calculatedDiscount(row.prodPrice, row.prodNum) }}
  32. </span>
  33. <span v-else>{{ row[item.prop] }}</span>
  34. </template>
  35. </el-table-column>
  36. <el-table-column align="center" label="操作" width="68px">
  37. <template #default="{ row }">
  38. <el-button type="text" @click="handleDel(row)">删除</el-button>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. </div>
  43. </template>
  44. <script>
  45. import AmountInput from '@/components/currency'
  46. export default {
  47. name: 'ProductTable',
  48. components: {
  49. AmountInput,
  50. },
  51. props: {
  52. productData: {
  53. type: Array,
  54. default() {
  55. return []
  56. },
  57. },
  58. checkList: {
  59. type: Array,
  60. default() {
  61. return []
  62. },
  63. },
  64. },
  65. data() {
  66. return {
  67. data: [],
  68. columns: [
  69. {
  70. label: '产品编码',
  71. width: 'auto',
  72. prop: 'prodCode',
  73. },
  74. {
  75. label: '产品名称',
  76. width: 'auto',
  77. prop: 'prodName',
  78. },
  79. {
  80. label: '产品类别',
  81. width: 'auto',
  82. prop: 'prodClass',
  83. },
  84. {
  85. label: '产品单价',
  86. width: 'auto',
  87. prop: 'prodPrice',
  88. },
  89. {
  90. label: '数量',
  91. width: 'auto',
  92. prop: 'prodNum',
  93. },
  94. ],
  95. }
  96. },
  97. watch: {
  98. productData() {
  99. this.data = []
  100. this.data = this.productData.map((item) => {
  101. return { ...item, prodPrice: item['prodPrice'] }
  102. })
  103. console.log(this.data)
  104. },
  105. },
  106. created() {
  107. this.data = []
  108. this.data = this.productData.map((item) => {
  109. return { ...item, prodPrice: item['prodPrice'] }
  110. })
  111. },
  112. methods: {
  113. // input修改
  114. handleChange(row) {
  115. console.log('row', row)
  116. this.$emit('changeProductData', row)
  117. },
  118. // 删除
  119. handleDel(row) {
  120. this.$emit('delProductData', row)
  121. },
  122. // 计算总价
  123. calculatedDiscount(price, count) {
  124. let intPrice = price * 100
  125. return this.formatPrice((intPrice * count) / 100)
  126. },
  127. },
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. .custom-table-container {
  132. :deep() {
  133. i {
  134. cursor: pointer;
  135. }
  136. }
  137. .stripe-panel,
  138. .border-panel {
  139. margin: 0 10px #{$base-margin/2} 10px !important;
  140. }
  141. }
  142. </style>
  143. <style lang="scss">
  144. .table-container {
  145. width: 100%;
  146. }
  147. </style>