com-attr.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <style>
  2. .com-attr .box {
  3. line-height: 64px;
  4. border-top: 1px solid #E8EAEE;
  5. border-left: 1px solid #E8EAEE;
  6. border-right: 1px solid #E8EAEE;
  7. padding: 0 16px;
  8. }
  9. .com-attr .box .batch {
  10. margin-left: -10px;
  11. margin-right: 20px;
  12. }
  13. .com-attr .el-select .el-input {
  14. width: 130px;
  15. }
  16. .com-attr .input-with-select .el-input-group__prepend {
  17. background-color: #fff;
  18. }
  19. .com-attr .header-require:before {
  20. content: '*';
  21. color: #F56C6C;
  22. margin-right: 2px;
  23. }
  24. </style>
  25. <template id="com-attr">
  26. <div class="com-attr">
  27. <el-table ref="multipleTable" :data="cData" border stripe style="width: 100%"
  28. @selection-change="handleSelectionChange">
  29. <el-table-column
  30. v-for="(item, index) in attrGroups"
  31. :key="item.id"
  32. :prop="'attr_list['+index+'].attr_name'"
  33. :label="item.attr_group_name">
  34. </el-table-column>
  35. <el-table-column v-if="cList"
  36. v-for="(item, key, index) in cList"
  37. :key="item.id"
  38. :property="key"
  39. :label="item + (append ? '(' + append + ')' : '')"
  40. >
  41. <template slot="header" v-if="key===`price` || key=== `stock` || key===`group_buy_price`">
  42. </template>
  43. <template slot-scope="scope">
  44. <template >
  45. <div flex="box:first" v-if="scope.column.property == 'pic_url'" style="padding: 10px" >
  46. <div flex="cross:center" style="margin-right: 10px;position: relative;">
  47. <com-attachment :multiple="false" :params="scope.row" :max="1"
  48. v-model="scope.row[scope.column.property]">
  49. <com-gallery :url="scope.row[scope.column.property]"
  50. width="50px" height="50px"></com-gallery>
  51. </com-attachment>
  52. <el-button v-if="scope.row[scope.column.property]" style="position: absolute; right: -8px; top: -8px; padding: 4px 4px;"
  53. size="mini" type="danger" icon="el-icon-close" circle
  54. @click="scope.row[scope.column.property] = ''"></el-button>
  55. </div>
  56. </div>
  57. <el-input :disabled="!scope.column.property == 'group_buy_price'"
  58. v-else-if="scope.column.property == 'group_buy_price'"
  59. type="number" v-model="scope.row[scope.column.property]" @blur="itemInput(scope.column.property,scope.row[scope.column.property])">
  60. </el-input>
  61. <el-input :disabled="!(scope.column.property == 'group_buy_price'||scope.column.property == 'stock') "
  62. v-else-if="scope.column.property.indexOf('price') > -1 || scope.column.property.indexOf('level')"
  63. oninput="this.value = this.value.replace(/[^0-9]/g, '');"
  64. type="number" v-model="scope.row[scope.column.property]" @blur="itemInput(scope.column.property,scope.row[scope.column.property])">
  65. </el-input>
  66. <el-input v-else oninput="this.value = this.value.replace(/[^0-9]/g, '');" v-model="scope.row[scope.column.property]">
  67. <template v-if="append" slot="append">{{append}}</template>
  68. </el-input>
  69. </template>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. </div>
  74. </template>
  75. <script>
  76. Vue.component('com-attr', {
  77. template: '#com-attr',
  78. props: {
  79. value: Array, // 商品规格信息
  80. attrGroups: Array, // 商品规格组
  81. extra: Object, // 额外的数据信息
  82. list: Object | Array, // 从排列数据信息
  83. append: String, // 输入框后缀
  84. },
  85. data() {
  86. return {
  87. attrBatch: false,
  88. data: {
  89. price: '原价',
  90. group_buy_price: '拼团价',
  91. stock: '规格库存',
  92. weight: '重量(克)',
  93. no: '货号',
  94. },
  95. selectData: '',
  96. batch: 0,
  97. selectList: [],
  98. };
  99. },
  100. created() {
  101. },
  102. watch: {
  103. 'selectList'(oldData, newData) {
  104. const self = this;
  105. let sign = 0;
  106. this.value.forEach(function (item, index) {
  107. self.selectList.map((item1) => {
  108. if (JSON.stringify(item1.attr_list) === JSON.stringify(item.attr_list)) {
  109. sign++;
  110. }
  111. });
  112. });
  113. self.attrBatch = self.value.length === sign;
  114. }
  115. },
  116. computed: {
  117. cList() {
  118. return this.data;
  119. },
  120. cData() {
  121. if (this.attrGroups && this.attrGroups.length > 0 && this.attrGroups[0].attr_list.length === 0) {
  122. return [];
  123. } else {
  124. return this.value;
  125. }
  126. }
  127. },
  128. methods: {
  129. itemInput(e,f){
  130. if(e=='stock'){
  131. }
  132. },
  133. selectClick() {
  134. this.$refs.multipleTable.toggleAllSelection();
  135. },
  136. handleSelectionChange(data) {
  137. this.selectList = data;
  138. },
  139. batchAttr(param) {
  140. if (!param) {
  141. this.$message.warning('请选择批量设置');
  142. return;
  143. }
  144. if (!this.selectList || this.selectList.length === 0) {
  145. this.$message.warning('请勾选商品规格');
  146. return;
  147. }
  148. }
  149. }
  150. });
  151. </script>