com-attr.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. .text .el-input-group__append{
  25. padding: 0 10px;
  26. }
  27. </style>
  28. <template id="com-attr">
  29. <div class="com-attr">
  30. <div class="box">
  31. <el-checkbox v-model="attrBatch" @change="selectClick" :disabled="!cData || cData.length == 0"
  32. style="position:absolute">全选
  33. </el-checkbox>
  34. <el-form-item label="批量设置" style="margin-bottom:0;padding:18px 0">
  35. <el-input @keyup.enter.native="batchAttr(selectData)"
  36. :type="selectData == 'no' ? 'text' : 'number'" v-model="batch">
  37. <el-select v-model="selectData" slot="prepend">
  38. <el-option v-for="(item, index) in cList" :value="index" :key="index" v-if="index!='pic_url'" :label="item+''">{{item}}
  39. </el-option>
  40. </el-select>
  41. <template slot="append">
  42. <el-button @click="batchAttr(selectData)">
  43. 确定
  44. </el-button>
  45. </template>
  46. </el-input>
  47. </el-form-item>
  48. </div>
  49. <el-table ref="multipleTable" :data="cData" border stripe style="width: 100%"
  50. @selection-change="handleSelectionChange">
  51. <el-table-column type="selection" width="55"></el-table-column>
  52. <el-table-column
  53. v-for="(item, index) in attrGroups"
  54. :key="item.id"
  55. :prop="'attr_list['+index+'].attr_name'"
  56. :label="item.attr_group_name">
  57. </el-table-column>
  58. <el-table-column v-if="cList"
  59. v-for="(item, key, index) in cList"
  60. :key="index"
  61. :property="key"
  62. :label="item + (append ? '(' + append + ')' : '')">
  63. <template slot="header" v-if="key===`price` || key=== `stock`|| key=== `original_price`||key=== `cost_price`">
  64. <div class="header-require">{{item}}</div>
  65. </template>
  66. <template slot-scope="scope">
  67. <template v-if="!isLevel">
  68. <div flex="box:first" v-if="scope.column.property == 'pic_url'" style="padding: 10px;">
  69. <div flex="cross:center" style="margin-right: 10px;position: relative;">
  70. <com-attachment :multiple="false" :params="scope.row" :max="1"
  71. v-model="scope.row[scope.column.property]">
  72. <com-gallery :url="scope.row[scope.column.property]"
  73. width="50px" height="50px"></com-gallery>
  74. </com-attachment>
  75. <el-button v-if="scope.row[scope.column.property]" style="position: absolute; right: -8px; top: -8px; padding: 4px 4px;"
  76. size="mini" type="danger" icon="el-icon-close" circle
  77. @click="scope.row[scope.column.property] = ''"></el-button>
  78. </div>
  79. </div>
  80. <el-input v-else-if="scope.column.property == 'no'" v-model="scope.row[scope.column.property]"></el-input>
  81. <!-- <div v-else-if="scope.column.property.indexOf('price') > -1 || scope.column.property.indexOf('level')">{{scope.column.property}}</div> -->
  82. <el-input v-else-if="scope.column.property.indexOf('price') > -1 || scope.column.property.indexOf('level')" type="number" v-model="scope.row[scope.column.property]"></el-input>
  83. <el-input v-else oninput="this.value = this.value.replace(/[^0-9]/g, '');" v-model="scope.row[scope.column.property]">
  84. <template v-if="append" slot="append">{{append}}</template>
  85. </el-input>
  86. </template>
  87. <template v-else>
  88. <el-input :data-id="scope.row[scope.column.label]" type="number" class="text"
  89. v-model="scope.row[memberSettingKey][scope.column.property]">
  90. <template v-if="scope.row.levelPrice && scope.row.levelPrice[scope.column.property] >= 0" slot="append" style="padding: 10px;">参考价:{{scope.row.levelPrice[scope.column.property]}}元</template>
  91. </el-input>
  92. </template>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. </div>
  97. </template>
  98. <script>
  99. Vue.component('com-attr', {
  100. template: '#com-attr',
  101. props: {
  102. value: Array, // 商品规格信息
  103. attrGroups: Array, // 商品规格组
  104. extra: Object, // 额外的数据信息
  105. list: Object | Array, // 从排列数据信息
  106. isLevel: Boolean, // 是否是会员
  107. members: Array, // 会员等级列表
  108. share: Array, // 分销等级列表
  109. append: String, // 输入框后缀
  110. paramKey: {
  111. type: String,
  112. default() {
  113. return 'member_price';
  114. }
  115. }
  116. },
  117. data() {
  118. return {
  119. attrBatch: false,
  120. data: {
  121. original_price: '划线价',
  122. cost_price: '成本价',
  123. price: '售价',
  124. stock: '库存',
  125. weight: '重量(克)',
  126. no: '货号',
  127. //pic_url: '规格图片',
  128. },
  129. selectData: '',
  130. batch: 0,
  131. selectList: [],
  132. memberSettingKey: 'member_price_setting',
  133. };
  134. },
  135. created() {
  136. let that = this;
  137. // console.info(this.value,"members");
  138. if (this.isLevel) {
  139. for (let i in this.value){
  140. if (this.value[i][this.memberSettingKey]) {
  141. continue;
  142. }
  143. let price_key = this.value[i].sign_id;
  144. let members = JSON.parse(JSON.stringify(this.members));
  145. let obj = {};
  146. members.forEach(function (memberLevelItem, memberLevelIndex) {
  147. let key = 'level' + memberLevelItem.level;
  148. // console.info(memberLevelItem.value,"memberLevelItem.value",price_key)
  149. if (memberLevelItem.value && JSON.stringify(memberLevelItem.value) != "{}") {
  150. memberLevelItem.value[price_key] = memberLevelItem.value[price_key]?memberLevelItem.value[price_key]:0;
  151. that.$set(obj,key,memberLevelItem.value[price_key]);
  152. } else {
  153. that.$set(obj,key,0);
  154. }
  155. });
  156. that.$set(this.value[i],this.memberSettingKey,obj);
  157. }
  158. console.info(this.value);
  159. }
  160. },
  161. watch: {
  162. 'selectList'(oldData, newData) {
  163. const self = this;
  164. let sign = 0;
  165. this.value.forEach(function (item, index) {
  166. self.selectList.map((item1) => {
  167. if (JSON.stringify(item1.attr_list) === JSON.stringify(item.attr_list)) {
  168. sign++;
  169. }
  170. });
  171. });
  172. self.attrBatch = self.value.length === sign;
  173. },
  174. },
  175. computed: {
  176. cList() {
  177. // TODO 分销数据暂时
  178. if (this.share) {
  179. let share = JSON.parse(JSON.stringify(this.share));
  180. let obj = {};
  181. for (let i = 0; i < share.length; i++) {
  182. obj[share[i].value] = share[i].label;
  183. }
  184. return obj;
  185. }
  186. // TODO 会员数据暂时
  187. if (this.isLevel) {
  188. let members = JSON.parse(JSON.stringify(this.members));
  189. let obj = {};
  190. for (let i = 0; i < members.length; i++) {
  191. obj['level' + members[i].level] = members[i].name
  192. }
  193. return obj;
  194. } else {
  195. if (this.extra) {
  196. return Object.assign(this.data, JSON.parse(JSON.stringify(this.extra)));
  197. } else if (this.list) {
  198. return JSON.parse(JSON.stringify(this.list))
  199. } else {
  200. return this.data;
  201. }
  202. }
  203. },
  204. cData() {
  205. if (this.attrGroups && this.attrGroups.length > 0 && this.attrGroups[0].attr_list.length === 0) {
  206. return [];
  207. } else {
  208. return this.value;
  209. }
  210. }
  211. },
  212. methods: {
  213. selectClick() {
  214. this.$refs.multipleTable.toggleAllSelection();
  215. },
  216. handleSelectionChange(data) {
  217. this.selectList = data;
  218. },
  219. batchAttr(param) {
  220. if (!param) {
  221. this.$message.warning('请选择批量设置');
  222. return;
  223. }
  224. if (!this.selectList || this.selectList.length === 0) {
  225. this.$message.warning('请勾选商品规格');
  226. return;
  227. }
  228. let self = this;
  229. let batch = self.batch;
  230. this.value.forEach((item, index) => {
  231. console.info(item,self.selectList);
  232. let sign = false;
  233. self.selectList.map((item1) => {
  234. if (JSON.stringify(item1.attr_list) === JSON.stringify(item.attr_list)) {
  235. sign = true;
  236. }
  237. });
  238. if (sign) {
  239. // 批量设置会员价
  240. // 判断字符串是否出现过,并返回位置
  241. console.info(param);
  242. if (param.indexOf('level') !== -1) {
  243. // item[this.paramKey][param] = batch;
  244. // item.levelPrice[param] = batch;
  245. item[self.memberSettingKey][param] = batch;
  246. } else {
  247. self.$set(item,param,batch)
  248. // item[memberSettingKey][param] = batch;
  249. }
  250. }
  251. });
  252. }
  253. }
  254. });
  255. </script>