param.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. define({
  2. template: `
  3. <div>
  4. <div class="vue-main-title">
  5. <div class="vue-main-title-left"></div>
  6. <div class="vue-main-title-content">商品属性</div>
  7. </div>
  8. <ul class="attributes">
  9. <ul class="attribute-row">
  10. <li class="attribute-col">
  11. 属性名称
  12. </li>
  13. <li class="attribute-col">
  14. 属性值
  15. </li>
  16. <li class="attribute-col"></li>
  17. </ul>
  18. <draggable v-model="attributes">
  19. <ul class="attribute-row" v-for="(attrItem,itemIndex) in attributes" :key="attrItem.itemIndex">
  20. <li class="attribute-col">
  21. <el-input v-model="attrItem.title" placeholder="请输入属性名称"></el-input>
  22. </li>
  23. <li class="attribute-col">
  24. <el-input v-model="attrItem.value" placeholder="请输入属性值"></el-input>
  25. </li>
  26. <li class="attribute-col">
  27. <el-button icon="el-icon-rank"></el-button>
  28. <el-button icon="el-icon-delete" @click="removeAttr(itemIndex)"></el-button>
  29. </li>
  30. </ul>
  31. </draggable>
  32. </ul>
  33. <el-button style="margin-top:20px;" @click="addAttr">添加属性</el-button>
  34. </div>
  35. `,
  36. style: `
  37. .attribute-row {
  38. display:flex;
  39. align:center;
  40. justify-content:space-around;
  41. padding:18px 0;
  42. font-size:14px;
  43. color:#101010;
  44. border-bottom:1px solid #e8e8e8;
  45. }
  46. `,
  47. props: {
  48. form: {
  49. default() {
  50. return {};
  51. },
  52. },
  53. },
  54. data() {
  55. return {
  56. attributes: [],
  57. };
  58. },
  59. mounted() {
  60. // console.log(this.form,5)
  61. this.attributes = this.form.map(item => ({id:item.id,'title':item.title,'value':item.value}))
  62. },
  63. methods: {
  64. removeAttr(itemIndex) {
  65. this.attributes.splice(itemIndex, 1);
  66. },
  67. addAttr() {
  68. this.attributes.push({
  69. id: "",
  70. title: "",
  71. value: "",
  72. });
  73. },
  74. extraDate(){
  75. },
  76. validate() {
  77. let yes = true;
  78. // 过滤空数据
  79. this.attributes.forEach(element => {
  80. if(!element.title || !element.value){
  81. this.$message.error('请输入属性名和属性值');
  82. yes = false;
  83. return
  84. }
  85. });
  86. if (yes) {
  87. return this.attributes;
  88. } else {
  89. return false;
  90. }
  91. },
  92. },
  93. });