com-attr.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. <div class="box">
  28. <el-checkbox v-model="attrBatch" @change="selectClick" :disabled="!cData || cData.length == 0" style="position:absolute">全选
  29. </el-checkbox>
  30. <el-form-item label="批量设置" style="margin-bottom:0;padding:18px 0">
  31. <el-input @keyup.enter.native="batchAttr(selectData)" :type="selectData == 'no' ? 'text' : 'number'" v-model="batch">
  32. <el-select v-model="selectData" slot="prepend">
  33. <el-option v-for="(item, index) in extraField" :value="index" :key="index" v-if="index!='pic_url'" :label="item+''">{{item}}
  34. </el-option>
  35. </el-select>
  36. <template slot="append">
  37. <el-button @click="batchAttr(selectData)">
  38. 确定
  39. </el-button>
  40. </template>
  41. </el-input>
  42. </el-form-item>
  43. </div>
  44. <el-table ref="multipleTable" :data="cData" border stripe style="width: 100%" @selection-change="handleSelectionChange" :key="itemKey">
  45. <el-table-column type="selection" width="70">
  46. </el-table-column>
  47. <el-table-column v-for="(item, index) in attrGroups" :key="item.id" :prop="'attr_list['+index+'].attr_name'" :label="'规格'">
  48. </el-table-column>
  49. <el-table-column v-if="cList" v-for="(item, key, index) in cList" :key="item.id" :property="key" :label="item + (append ? '(' + append + ')' : '')">
  50. <!-- <template slot="header" v-if="key===`price` || key=== `stock` || key===`deposit_presale_price`">
  51. </template> -->
  52. <template slot-scope="scope">
  53. <template>
  54. <div flex="box:first" v-if="scope.column.property == 'goods_name'" style="padding: 10px">
  55. <div flex="cross:center" style="margin-right: 10px;position: relative;">
  56. <com-attachment :multiple="false" :params="scope.row" :max="1" v-model="goodsDetail.cover_pic">
  57. <com-gallery :url="goodsDetail.cover_pic" width="50px" height="50px"></com-gallery>
  58. </com-attachment>
  59. <span>{{goodsDetail.goods_name}}</span>
  60. </div>
  61. </div>
  62. <el-input :disabled="!(scope.column.property == 'deposit_presale_price' || scope.column.property == 'deposit_price' || scope.column.property == 'deposit_stock' || scope.column.property == 'purchase_limit_num')" v-else-if="(scope.column.property == 'deposit_presale_price' || scope.column.property == 'deposit_price' || scope.column.property == 'deposit_stock' || scope.column.property == 'purchase_limit_num')" type="number" v-model="scope.row[scope.column.property]" @blur="itemInput(scope.column.property,scope.row[scope.column.property], scope.row.id)">
  63. </el-input>
  64. <el-input :disabled="!(scope.column.property == 'deposit_presale_price' || scope.column.property == 'deposit_price' || scope.column.property == 'deposit_stock' || scope.column.property == 'purchase_limit_num') " v-else-if="scope.column.property.indexOf('price') > -1 || scope.column.property.indexOf('level')" type="number" v-model="scope.row[scope.column.property]" @blur="itemInput(scope.column.property,scope.row[scope.column.property], scope.row.id)">
  65. </el-input>
  66. <!-- <el-input :disabled="!(scope.column.property == 'deposit_presale_price' || scope.column.property == 'deposit_price' || scope.column.property == 'deposit_stock' || scope.column.property == 'limit_buy') " v-else-if="scope.column.property.indexOf('price') > -1 || scope.column.property.indexOf('level')" oninput="this.value = this.value.replace(/[^0-9]/g, '');" type="number" v-model="scope.row[scope.column.property]" @blur="itemInput(scope.column.property,scope.row[scope.column.property], scope.row.id)">
  67. </el-input> -->
  68. <!-- <el-input v-else oninput="this.value = this.value.replace(/[^0-9]/g, '');" v-model="scope.row[scope.column.property]">
  69. <template v-if="append" slot="append">{{append}}</template>
  70. </el-input> -->
  71. </template>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. </div>
  76. </template>
  77. <script>
  78. Vue.component('com-attr', {
  79. template: '#com-attr',
  80. props: {
  81. value: Array, // 商品规格信息
  82. attrGroups: Array, // 商品规格组
  83. extra: Object, // 额外的数据信息
  84. list: Object | Array, // 从排列数据信息
  85. append: String, // 输入框后缀
  86. goodsDetail: Object,
  87. activeGoodsAttr: Array,
  88. },
  89. data() {
  90. return {
  91. attrBatch: false,
  92. data: {
  93. goods_name: '商品',
  94. // name: '规格',
  95. price: '售价',
  96. stock: '库存',
  97. deposit_presale_price: '预售价',
  98. deposit_price: '定金',
  99. deposit_stock: '预售库存',
  100. purchase_limit_num: '限购',
  101. },
  102. extraField: {
  103. 'deposit_presale_price': '预售价',
  104. 'deposit_price': '定金',
  105. 'deposit_stock': '预售库存',
  106. 'purchase_limit_num': '限购'
  107. },
  108. selectData: '',
  109. batch: 0,
  110. selectList: [],
  111. itemKey: ''
  112. };
  113. },
  114. created() {
  115. console.log('-----------q23e2qw2',this.activeGoodsAttr, this.value);
  116. for (var i = 0; i < this.value.length; i++) {
  117. if (this.activeGoodsAttr.length > 0) {
  118. for (var j = 0; j < this.activeGoodsAttr.length; j++) {
  119. if (this.activeGoodsAttr[j]['attr_id'] == this.value[i]['id']) {
  120. this.value[i]['deposit_presale_price'] = this.activeGoodsAttr[j]['deposit_presale_price'];
  121. this.value[i]['deposit_price'] = this.activeGoodsAttr[j]['deposit_price'];
  122. this.value[i]['deposit_stock'] = this.activeGoodsAttr[j]['stock'];
  123. this.value[i]['purchase_limit_num'] = this.activeGoodsAttr[j]['purchase_limit_num'];
  124. }
  125. }
  126. } else {
  127. this.value[i]['deposit_presale_price'] = 0;
  128. this.value[i]['deposit_price'] = 0;
  129. this.value[i]['deposit_stock'] = 0;
  130. this.value[i]['purchase_limit_num'] = 0;
  131. }
  132. }
  133. },
  134. watch: {
  135. 'selectList'(oldData, newData) {
  136. const self = this;
  137. let sign = 0;
  138. this.value.forEach(function(item, index) {
  139. self.selectList.map((item1) => {
  140. if (JSON.stringify(item1.attr_list) === JSON.stringify(item.attr_list)) {
  141. sign++;
  142. }
  143. });
  144. });
  145. self.attrBatch = self.value.length === sign;
  146. }
  147. },
  148. computed: {
  149. cList() {
  150. return this.data;
  151. },
  152. cData() {
  153. // this.itemKey = Math.random()
  154. if (this.attrGroups && this.attrGroups.length > 0 && this.attrGroups[0].attr_list.length === 0) {
  155. return [];
  156. } else {
  157. let list = JSON.parse(JSON.stringify(this.value))
  158. return list;
  159. }
  160. }
  161. },
  162. methods: {
  163. itemInput(e, f, index) {
  164. for (var i = 0; i < this.selectList.length; i++) {
  165. for (let key in this.selectList[i]) {
  166. if (key == f) {
  167. this.selectList[i][key] = this.batch;
  168. }
  169. }
  170. }
  171. console.log(e, f, index);
  172. for (var i = 0; i < this.value.length; i++) {
  173. for (var key in this.value[i]) {
  174. if (key == 'id' && this.value[i][key] == index) {
  175. this.value[i][e] = f;
  176. }
  177. }
  178. }
  179. },
  180. selectClick() {
  181. this.$refs.multipleTable.toggleAllSelection();
  182. },
  183. handleSelectionChange(data) {
  184. this.selectList = data;
  185. },
  186. batchAttr(param) {
  187. if (!param) {
  188. this.$message.warning('请选择批量设置');
  189. return;
  190. }
  191. if (!this.selectList || this.selectList.length === 0) {
  192. this.$message.warning('请勾选商品规格');
  193. return;
  194. }
  195. var id_arr = [];
  196. for (var i = 0; i < this.selectList.length; i++) {
  197. for (let key in this.selectList[i]) {
  198. if (param == key) {
  199. this.selectList[i][key] = this.batch;
  200. id_arr.push(this.selectList[i]['id'])
  201. }
  202. }
  203. }
  204. for (var i = 0; i < this.value.length; i++) {
  205. for(var key in this.value[i]){
  206. if (id_arr.indexOf(this.value[i]['id']) > -1) {
  207. this.value[i][param] = this.batch;
  208. }
  209. }
  210. }
  211. // this.itemKey = Math.random();
  212. this.batch = '';
  213. }
  214. }
  215. });
  216. </script>