spec_info.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. define({
  2. template: `
  3. <div>
  4. <el-form ref="auth">
  5. <div class="vue-main-title">
  6. <div class="vue-main-title-left"></div>
  7. <div class="vue-main-title-content">规格信息</div>
  8. </div>
  9. <div style="margin:0 auto;width:90%;">
  10. <el-form-item label=" ">
  11. <el-table :data="spec_info" style="width: 100%">
  12. <el-table-column prop="sort" label="排序" width='150' >
  13. <template slot-scope="scope">
  14. <el-input v-model="scope.row.sort" placeholder=""></el-input>
  15. </template>
  16. </el-table-column>
  17. <el-table-column prop="info_img" label="图片" width='250' >
  18. <template slot-scope="scope">
  19. <div class="upload-boxed" @click="displaySelectMaterialPopup('info_img',scope.$index)">
  20. <img
  21. :src="scope.row.info_img_src"
  22. style="width: 150px; height: 150px; border-radius: 5px; cursor: pointer;object-fit:cover;"
  23. v-show="scope.row.info_img_src"
  24. />
  25. <div class="el-icon-plus" v-show="!scope.row.info_img_src"></div>
  26. <div class="upload-boxed-text">点击重新上传</div>
  27. </div>
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="desc" label="内容" width='350' >
  31. <template slot-scope="scope">
  32. <el-input v-for="(item,index) in scope.row.content" v-model="item.content" maxlength="12" show-word-limit></el-input>
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="规格">
  36. <template slot-scope="scope">
  37. <el-select v-model="scope.row.goods_option_id" placeholder="请选择">
  38. <el-option
  39. v-for="item in goods_options"
  40. :key="item.id"
  41. :label="item.title"
  42. :value="item.id">
  43. </el-option>
  44. </el-select>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="">
  48. <template slot-scope="scope">
  49. <el-button @click="delSpecInfo(scope.$index)"><i class="el-icon-delete"></i></el-button>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <el-button icon="el-icon-plus" @click="addSpecInfo">添加</el-button>
  54. <div class="form-item_tips">
  55. 排序大的显示在前面,图片建议尺寸:请上传,或正方形图片,文字最多显示12个<br>
  56. 注意:如是发布商品,请先保存商品后才能进行关联规格,关联规格时注意规格有大的整体变动(例:删除某些规格项),如有也请先保存商品信息后再进行关联,否则可能关联到失效规格
  57. </div>
  58. </el-form-item>
  59. </div>
  60. </el-form>
  61. <upload-multimedia-img
  62. :upload-show="showSelectMaterialPopup"
  63. :type="materialType"
  64. :name="formFieldName"
  65. selNum="one"
  66. @replace="showSelectMaterialPopup = !showSelectMaterialPopup"
  67. @sure="selectedMaterial"
  68. ></upload-multimedia-img>
  69. </div>
  70. `,
  71. props: {
  72. form: {
  73. default() {
  74. return {};
  75. },
  76. },
  77. formKey: {
  78. type: String,
  79. },
  80. },
  81. data() {
  82. return {
  83. showSelectMaterialPopup: false,
  84. formFieldName: "",
  85. materialType: "",
  86. selNum: "one",
  87. select:"open",
  88. goods_options:[],
  89. spec_info:[],
  90. img_index:"",
  91. };
  92. },
  93. created() {
  94. this.goods_options = this.form.options;
  95. this.spec_info = this.form.specs_info;
  96. // console.log(this.goods_options,this.spec_info,'规格信息123')
  97. },
  98. methods: {
  99. extraDate(){
  100. return {
  101. 'extraContent':"商品描述"
  102. }
  103. },
  104. displaySelectMaterialPopup(fieldName = "thumb",index,type = 1) {
  105. if(fieldName == 'other'){
  106. this.selNum = 'more'
  107. }else{
  108. this.selNum = 'one'
  109. }
  110. this.img_index = index;
  111. this.formFieldName = fieldName;
  112. this.showSelectMaterialPopup = !this.showSelectMaterialPopup;
  113. this.materialType = String(type);
  114. },
  115. selectedMaterial(name, image, imageUrl) {
  116. let originalImageUrl = JSON.parse(JSON.stringify(imageUrl))
  117. if (Array.isArray(imageUrl)) {
  118. imageUrl = imageUrl.map((item) => {
  119. return item.url;
  120. });
  121. }
  122. console.log(originalImageUrl[0],this.img_index,this.formFieldName);
  123. this.spec_info[this.img_index][this.formFieldName] = originalImageUrl[0].attachment;
  124. this.spec_info[this.img_index][this.formFieldName+'_src'] = originalImageUrl[0].url;
  125. this.spec_info.push({});
  126. this.spec_info.splice(this.spec_info.length-1,1)
  127. this.$forceUpdate();
  128. },
  129. changeGoodsImage(index,val) {
  130. this.goodsImagesChangeIndex = index;
  131. this.displayUploadImagePopup("images");
  132. },
  133. addSpecInfo() {
  134. this.spec_info.push({
  135. goods_option_id:"",
  136. info_img:"",
  137. info_img_src:"",
  138. sort:"",
  139. content: [{content:""},{content:""},{content:""},{content:""},{content:""},{content:""}]
  140. });
  141. },
  142. delSpecInfo(index) {
  143. this.spec_info.splice(index,1);
  144. },
  145. validate() {
  146. return {
  147. spec_info:this.spec_info ? this.spec_info : []
  148. }
  149. },
  150. },
  151. });