You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.8 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. <script>
  2. import {queryQuoteDetailReportByTP} from "../../../../api/quote/quoteDetail";
  3. export default {
  4. name: "tpCost",
  5. props:{
  6. quoteDetail:{
  7. type:Object,
  8. required:true
  9. },
  10. height:{
  11. type:[String,Number],
  12. default:300
  13. }
  14. },
  15. data(){
  16. return{
  17. queryLoading:false,
  18. dataList:[],
  19. }
  20. },
  21. methods:{
  22. handleQuery(){
  23. let params = {
  24. id:this.quoteDetail.id
  25. }
  26. this.queryLoading = true;
  27. queryQuoteDetailReportByTP(params).then(({data})=>{
  28. if (data && data.code === 0){
  29. this.dataList = data.rows
  30. }else {
  31. this.queryLoading = false;
  32. }
  33. this.queryLoading = false;
  34. }).catch((error)=>{
  35. this.queryLoading = false;
  36. this.$message.error(error);
  37. })
  38. },
  39. alignIsNan(key,arr){
  40. for (let i = 0; i < arr.length; i++) {
  41. let item = arr[i];
  42. if (isNaN(item[key])){
  43. return 'left';
  44. }
  45. }
  46. return 'right';
  47. },
  48. flexColumnWidth (str, arr1, flag = 'max') {
  49. str = str + ''
  50. let columnContent = ''
  51. if (flag === 'equal') {
  52. // 获取该列中第一个不为空的数据(内容)
  53. for (let i = 0; i < arr1.length; i++) {
  54. if (arr1[i][str].length > 0) {
  55. // console.log('该列数据[0]:', arr1[0][str])
  56. columnContent = arr1[i][str]
  57. break
  58. }
  59. }
  60. } else {
  61. // 获取该列中最长的数据(内容)
  62. let index = 0
  63. for (let i = 0; i < arr1.length; i++) {
  64. if (arr1[i][str] === null) {
  65. continue
  66. }
  67. const now_temp = arr1[i][str] + ''
  68. const max_temp = arr1[index][str] + ''
  69. if (now_temp.length > max_temp.length) {
  70. index = i
  71. }
  72. }
  73. columnContent = arr1[index][str]+''
  74. }
  75. let flexWidth = 0
  76. if (columnContent && columnContent.length > 0){
  77. for (const char of columnContent) {
  78. if ((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z')) {
  79. // 如果是英文字符,为字符分配8个单位宽度
  80. flexWidth += 8
  81. } else if (char >= '\u4e00' && char <= '\u9fa5') {
  82. // 如果是中文字符,为字符分配15个单位宽度
  83. flexWidth += 15
  84. } else {
  85. // 其他种类字符,为字符分配8个单位宽度
  86. flexWidth += 8
  87. }
  88. }
  89. }
  90. let flexWidthStr = 0
  91. for (const char of str){
  92. if ((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z')) {
  93. // 如果是英文字符,为字符分配8个单位宽度
  94. flexWidthStr += 8
  95. } else if (char >= '\u4e00' && char <= '\u9fa5') {
  96. // 如果是中文字符,为字符分配15个单位宽度
  97. flexWidthStr += 15
  98. } else {
  99. // 其他种类字符,为字符分配8个单位宽度
  100. flexWidthStr += 8
  101. }
  102. }
  103. if (flexWidthStr > flexWidth){
  104. flexWidth = flexWidthStr
  105. }
  106. if (flexWidth < 120) {
  107. // 设置最小宽度
  108. flexWidth = 120
  109. }
  110. return flexWidth + 'px'
  111. }
  112. },
  113. watch:{
  114. quoteDetail(newVal,oldVal){
  115. if (newVal){
  116. this.handleQuery();
  117. }else {
  118. this.dataList = [];
  119. }
  120. },
  121. },
  122. computed:{
  123. objectKeys:{
  124. get(){
  125. return Object.keys(this.dataList[0] || {});
  126. }
  127. }
  128. }
  129. }
  130. </script>
  131. <template>
  132. <div>
  133. <el-table :data="dataList" border :height="height" v-loading="queryLoading">
  134. <el-table-column v-for="key in objectKeys" :align="alignIsNan(key,dataList)" header-align="center" :width="flexColumnWidth(key,dataList)" :key="key" :prop="key" :label="key"></el-table-column>
  135. </el-table>
  136. </div>
  137. </template>
  138. <style scoped>
  139. </style>