lj-cfgsel-tag.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="product-cfgsel-contanier">
  3. <div class="contanier-item" :class="isItemCls(textClass, item, i)" v-for="(item,i) in resultList" :key="i">
  4. <div class="item-title" v-if="item.flag == 4">
  5. {{item.title}}
  6. </div>
  7. <div class="item-value">
  8. {{item.value}}
  9. </div>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'lj-cfgsel-tag',
  16. components: {
  17. },
  18. props: {
  19. textValue: {
  20. type: String,
  21. default: ""
  22. },
  23. textFlag: {
  24. type: Number,
  25. default: -1
  26. },
  27. textClass: {
  28. type: Array,
  29. default: () => {
  30. return []
  31. }
  32. },
  33. },
  34. data(){
  35. return {
  36. resultList: []
  37. }
  38. },
  39. methods: {
  40. addCfgValue(value,flag){
  41. if(flag == 4 || flag == 0) {
  42. this.resultList = this.addValue(value,flag);
  43. } else {
  44. this.resultList.push(this.addValue(value,flag))
  45. }
  46. },
  47. addValue(value,flag) {
  48. if(flag == 4) {
  49. let arr = value.split('|');
  50. let result = [];
  51. arr.forEach((item) => {
  52. if(item.trim().length == 0) return;
  53. let index = item.indexOf(':');
  54. let a = item.substring(0,index++);
  55. let b = item.substring(index,item.length);
  56. result.push({flag:flag,title:a,value:b});
  57. })
  58. return result;
  59. }else if(flag == 0){
  60. return [{flag:flag,value:value}];
  61. }else {
  62. return {flag:flag,value:value};
  63. }
  64. }
  65. },
  66. created(){
  67. if(this.textValue.length > 0) this.addCfgValue(this.textValue,this.textFlag);
  68. },
  69. computed:{
  70. isItemCls(arr, item, idx) {
  71. return function (arr, item, idx) {
  72. if (!Array.isArray(arr) || arr.length < idx) {
  73. return ''
  74. }
  75. return arr[idx]
  76. }
  77. }
  78. },
  79. }
  80. </script>
  81. <style lang="less" scoped>
  82. .product-cfgsel-contanier {
  83. width: 100%;
  84. display: flex;
  85. flex-wrap: wrap;
  86. .contanier-item {
  87. border: 1px solid #ff976a;
  88. border-radius: 8px;
  89. display: flex;
  90. flex-wrap: nowrap;
  91. margin: 0 5px 5px 0;
  92. justify-content: space-between;
  93. align-content: center;
  94. overflow: hidden;
  95. font-size: 10px;
  96. .item-title {
  97. background-color: #ff976a;
  98. padding: 0 3px;
  99. // border-right: 1px solid #ff976a;
  100. border-radius: 0 8px 8px 0;
  101. text-align: center;
  102. flex-shrink: 0;
  103. color: #fff;
  104. }
  105. .item-value {
  106. padding: 0 3px;
  107. white-space:nowrap;
  108. overflow:hidden;
  109. text-overflow: ellipsis;
  110. }
  111. }
  112. }
  113. </style>