c_goods.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="goods-box" v-if="defaults.goodsList">
  3. <div class="wrapper">
  4. <draggable class="dragArea list-group" :list="defaults.goodsList.list" group="peoples">
  5. <div
  6. class="item"
  7. v-for="(goods, index) in defaults.goodsList.list"
  8. :key="index"
  9. v-if="defaults.goodsList.list.length"
  10. >
  11. <img :src="type == 1 ? goods.pic : goods.image" alt="" />
  12. <span class="iconfont icondel_1" @click.stop="bindDelete(index)"></span>
  13. </div>
  14. <div class="add-item item" @click="modals = true"><span class="iconfont iconaddto"></span></div>
  15. </draggable>
  16. </div>
  17. <Modal
  18. v-model="modals"
  19. :loading="loading"
  20. :title="titles"
  21. class="paymentFooter"
  22. :class="type ? '' : 'middleTop'"
  23. scrollable
  24. width="900"
  25. @on-cancel="cancel"
  26. @on-ok="ok"
  27. >
  28. <sort-list ref="goodslist" @getProductDiy="getProductDiy" v-if="modals && type == 1"></sort-list>
  29. <goods-list
  30. ref="goodslist"
  31. @getProductDiy="getProductDiy"
  32. :ischeckbox="true"
  33. :type="type"
  34. :is_new="is_new"
  35. :diy="true"
  36. v-if="modals && type != 1"
  37. ></goods-list>
  38. </Modal>
  39. </div>
  40. </template>
  41. <script>
  42. import vuedraggable from 'vuedraggable';
  43. import goodsList from '@/components/goodsList';
  44. import sortList from '@/components/sortList';
  45. export default {
  46. name: 'c_goods',
  47. props: {
  48. name: {
  49. type: String,
  50. },
  51. configData: {
  52. type: null,
  53. },
  54. configNum: {
  55. type: Number | String,
  56. default: 'default',
  57. },
  58. },
  59. components: {
  60. goodsList,
  61. sortList,
  62. draggable: vuedraggable,
  63. },
  64. watch: {
  65. configData: {
  66. handler(nVal, oVal) {
  67. this.defaults = nVal[this.configNum];
  68. let goodType = nVal[this.configNum].titleInfo ? nVal[this.configNum].titleInfo.type : 0;
  69. this.type = nVal[this.configNum].selectConfig.type
  70. ? nVal[this.configNum].selectConfig.type
  71. : goodType
  72. ? goodType
  73. : 0;
  74. switch (this.type) {
  75. case 0:
  76. this.titles = '商品列表';
  77. break;
  78. case 1:
  79. this.titles = '分类列表';
  80. break;
  81. case 8:
  82. this.titles = '砍价列表';
  83. break;
  84. case 2:
  85. this.titles = '秒杀列表';
  86. break;
  87. case 3:
  88. this.titles = '拼团列表';
  89. break;
  90. default:
  91. }
  92. },
  93. immediate: true,
  94. deep: true,
  95. },
  96. },
  97. data() {
  98. return {
  99. modals: false,
  100. goodsList: [],
  101. tempGoods: [],
  102. defaults: {},
  103. type: '',
  104. is_new: '',
  105. loading: true,
  106. titles: '',
  107. };
  108. },
  109. created() {
  110. this.defaults = this.configData[this.configNum];
  111. this.is_new = this.configData[this.configNum].is_new;
  112. },
  113. methods: {
  114. getProductDiy(data) {
  115. this.tempGoods = data;
  116. this.loading = false;
  117. },
  118. cancel() {
  119. this.tempGoods = [];
  120. },
  121. //对象数组去重;
  122. unique(arr) {
  123. const res = new Map();
  124. return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1));
  125. },
  126. ok() {
  127. if (!this.tempGoods.length) {
  128. return this.$Message.warning('请先选择商品');
  129. }
  130. let list = this.defaults.goodsList.list;
  131. list.push.apply(list, this.tempGoods);
  132. // list.push(this.tempGoods);
  133. let picList = this.unique(list);
  134. this.defaults.goodsList.list = picList;
  135. // this.defaults.goodsList.list.push(this.tempGoods);
  136. },
  137. bindDelete(index) {
  138. this.defaults.goodsList.list.splice(index, 1);
  139. },
  140. },
  141. };
  142. </script>
  143. <style scoped lang="stylus">
  144. .middleTop /deep/.ivu-modal-wrap .ivu-modal{
  145. top:50%!important;
  146. margin-top:-350px;
  147. }
  148. .goods-box
  149. padding 16px 0
  150. margin-bottom 16px
  151. border-top 1px solid rgba(0,0,0,0.05)
  152. border-bottom 1px solid rgba(0,0,0,0.05)
  153. .wrapper,.list-group
  154. display flex
  155. flex-wrap wrap
  156. .add-item
  157. display flex
  158. align-items center
  159. justify-content center
  160. width 80px
  161. height 80px
  162. margin-bottom 10px
  163. background #F7F7F7
  164. .iconfont
  165. font-size 18px
  166. color #D8D8D8
  167. .item
  168. position relative
  169. width 80px
  170. height 80px
  171. margin-bottom 20px
  172. margin-right 12px
  173. &:nth-child(4n)
  174. margin-right 0
  175. img
  176. width 100%
  177. height 100%
  178. .icondel_1
  179. position absolute
  180. right -10px
  181. top -16px
  182. color #999999
  183. font-size 28px
  184. cursor pointer
  185. </style>