style.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template id="store-style">
  2. <div>
  3. <diy-style-contain title="标题" class="clear-diy-style fill-border-top">
  4. <el-radio-group v-model="titleRadio" @change="radioChange($event, 'titleRadio')">
  5. <el-radio :label="0">隐藏</el-radio>
  6. <el-radio :label="1">显示</el-radio>
  7. </el-radio-group>
  8. <div style="padding-top: 10px" v-if="titleRadio == 1">
  9. <diy-operation-list v-model="titleList" :label-width="50" @on-change="onChange"></diy-operation-list>
  10. </div>
  11. </diy-style-contain>
  12. <diy-style-contain title="选择商家" class="clear-diy-style fill-border-top">
  13. <!-- <el-radio-group style="margin-bottom: 10px;" v-model="listType" @change="radioChange($event, 'listType')">
  14. <el-radio :label="0">指定商品</el-radio>
  15. <el-radio :label="1">所有商品</el-radio>
  16. </el-radio-group> -->
  17. <div class="pick-goods">
  18. <com-pick-link @selected="selectNavUrl" id-text="商品" :pick-type="pickType" :default-select-list="selectList" :default-tabs="[{name: 'marketing',children:['store'] }]">
  19. <div class="add-goods-btn">+添加({{ pickImgList.length + '/' + maxGroupLen }})</div>
  20. </com-pick-link>
  21. <div flex="cross:center" style="margin-top: 20px;flex-wrap:wrap" v-if="pickImgList.length">
  22. <div class="pickImgItem" v-for="(item,index) in pickImgList" :key="index" @mouseenter="mouseenter(index)" @mouseleave="mouseleave(index)">
  23. <el-image style="width: 50px; height: 50px" :src="item.params.img" fit="contain"></el-image>
  24. <div v-show="index == pickIndex || item.visible">
  25. <el-popover placement="bottom" v-model="item.visible">
  26. <p class="diy-del-text">确定删除吗?</p>
  27. <div flex="cross:center">
  28. <el-button class="diy-del-btn" size="mini" plain @click="delModel(index)">删除</el-button>
  29. <el-button size="mini" plain @click="item.visible = false">取消</el-button>
  30. </div>
  31. <i class="el-icon-close" slot="reference" style="color:#999;"></i>
  32. </el-popover>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </diy-style-contain>
  38. <diy-tabs title="组件边框设置" class="fill-border-top" radio_text='text' :default_item="defaultForm.tabItem" @change="colorSelect"></diy-tabs>
  39. <diy-color class="fill-border-top" :color-infos="colorInfos" :str-color="defColor" @chang="updateColor"></diy-color>
  40. <diy-size-setting class="fill-border-top" top-name="组件边距" :size-infos="sizeInfos" :size-infos-value="sizeInfosValue" :size-infos-max="sizeInfosMax" @chang="updateSize"></diy-size-setting>
  41. <diy-size-setting class="fill-border-top" top-name="圆角设置" :size-infos="defaultForm.radiusInfos" :max-value="20" @chang="RadiusChange"></diy-size-setting>
  42. </div>
  43. </template>
  44. <script>
  45. Vue.component('store-style', {
  46. name: "store-style",
  47. mixins: [basicMixins],
  48. template: '#store-style',
  49. props: {
  50. activeItem: {
  51. type: Object,
  52. default () {
  53. return {}
  54. }
  55. }
  56. },
  57. data() {
  58. return {
  59. titleRadio: 0,
  60. titleList: [{
  61. type: 'input',
  62. label: "文字",
  63. value: '新品推荐',
  64. max: 6,
  65. showLimit: true,
  66. setKey: "title",
  67. }, {
  68. type: "size",
  69. label: "上边距",
  70. value: 10,
  71. setKey: "paddingTop",
  72. maxValue: 20,
  73. }, {
  74. type: "size",
  75. label: "下边距",
  76. value: 10,
  77. setKey: "paddingBottom",
  78. maxValue: 20,
  79. }, ],
  80. // 选择商品
  81. listType: 0,
  82. pickType: ['store'],
  83. selGoodsList: [],
  84. maxGroupLen: 30,
  85. pickIndex: -1,
  86. btnData: {
  87. style: 0,
  88. name: '新品推荐'
  89. },
  90. // btnStyle: 0,
  91. // btnName: '立即拼团',
  92. colorInfos: ['底部背景', '内容背景'],
  93. defColor: ['#FAFAFA', '#FFFFFF'],
  94. sizeInfos: ['内容间距', '上边距', '下边距', '左右边距'],
  95. sizeInfosValue: [0, 0, 0, 0],
  96. sizeInfosMax: [50, 50, 50, 20],
  97. pickImgList: [],
  98. selectList: []
  99. }
  100. },
  101. methods: {
  102. init() {
  103. basicMixins.methods.init.call(this); // 以前的数据调用一下
  104. this.titleRadio = this.result.data.titleRadio || 0
  105. this.listType = this.result.data.listType || 0
  106. if (this.result.data.btnData) {
  107. this.btnData = this.result.data.btnData
  108. } else {
  109. this.result.data.btnData = this.btnData
  110. }
  111. // 选择商品
  112. let arr = ['data', 'goods']
  113. this.pickImgList = getObjValue(this.result, arr, [])
  114. this.initList('titleList')
  115. this.setDefaultSelectIds();
  116. },
  117. radioChange(e, name) {
  118. this.result.data[name] = e
  119. this.$emit("update", this.result)
  120. },
  121. btnChange(e, name) {
  122. console.log('55555输入内容',e,name)
  123. this.result.data.btnData[name] = e
  124. this.$emit("update", this.result)
  125. },
  126. onChange(e) {
  127. this.updataList('titleList')
  128. },
  129. selectNavUrl(e) {
  130. let self = this;
  131. e = e.filter(function (item) {
  132. if (self.selectList.length > 0) {
  133. return !self.selectList.includes(item.params.id);
  134. }
  135. return item;
  136. });
  137. this.pickImgList.push(...e)
  138. this.pickImgList = this.unique(this.pickImgList)
  139. if (this.pickImgList.length > this.maxGroupLen) {
  140. this.$message({
  141. message: `最多添加${this.maxGroupLen}件商品噢`,
  142. type: 'warning'
  143. });
  144. }
  145. this.pickImgList = this.pickImgList.slice(0, this.maxGroupLen)
  146. this.result.data.goods = this.pickImgList
  147. this.$emit("update", this.result)
  148. this.setDefaultSelectIds();
  149. },
  150. setDefaultSelectIds() {
  151. let pickData = this.pickImgList;
  152. let selectIds = [];
  153. pickData.forEach(item => {
  154. selectIds.push(item.params.id);
  155. })
  156. this.selectList = selectIds.filter((item, index, selectIds) => selectIds.indexOf(item) === index);
  157. },
  158. unique(arr) {
  159. for (var i = 0; i < arr.length; i++) {
  160. for (var j = i + 1; j < arr.length; j++) {
  161. if (arr[i].params.id == arr[j].params.id) {
  162. arr.splice(j, 1);
  163. j--;
  164. }
  165. }
  166. }
  167. return arr
  168. },
  169. getSelectList(arr) {
  170. if (arr.length == 0) return;
  171. this.selectList = []
  172. arr.forEach(item => {
  173. this.selectList.push(item.params.id)
  174. })
  175. console.log(this.selectList, '-----------this.selectList')
  176. },
  177. delModel(index) {
  178. // let arr = []
  179. // this.pickImgList.forEach((it, i) => {
  180. // if (i == index) {
  181. // arr.push(it)
  182. // }
  183. // })
  184. this.pickImgList.splice(index, 1)
  185. this.result.data.goods = this.pickImgList
  186. this.selectList.splice(index, 1);
  187. // this.getSelectList(this.pickImgList)
  188. this.$emit("update", this.result)
  189. },
  190. updataList(target) {
  191. this[target].map((item, index) => {
  192. var obj = {}
  193. if (item.setKey) {
  194. const key = item.setKey
  195. console.log(key, item.value)
  196. this.updateStyle(key, item.value)
  197. }
  198. return obj
  199. })
  200. },
  201. updateStyle(key, value) {
  202. var obj = this.result.data
  203. this.result.data = Object.assign(obj, {
  204. [key]: value
  205. })
  206. console.log(this.result.data)
  207. this.$emit("update", this.result)
  208. },
  209. initList(target) {
  210. var data = this.result.data
  211. if (this[target] && !this[target].length) {
  212. return false
  213. }
  214. var arr = this[target].map(item => {
  215. var obj = Object.assign(item, {
  216. value: item.value
  217. })
  218. if ((item.setKey in data) && data[item.setKey] !== "") {
  219. obj.value = data[item.setKey]
  220. }
  221. return obj
  222. });
  223. this[target] = arr
  224. },
  225. mouseenter(index) {
  226. this.pickIndex = index
  227. },
  228. mouseleave() {
  229. this.pickIndex = -1
  230. },
  231. delModel(index) {
  232. this.pickImgList.splice(index, 1)
  233. this.result.data.goods = this.pickImgList
  234. this.$emit("update", this.result)
  235. },
  236. updateColor(data) { // 选择颜色
  237. console.log("updateColor parent", data)
  238. this.updateSome(data, 'colorInfos')
  239. let style = this.result.computedStyle
  240. let colorArr = ['boxBg', 'goodsBg']
  241. colorArr.forEach((it, i) => {
  242. this.result.computedStyle = Object.assign(style, {
  243. [it]: this.colorInfos[i].color
  244. })
  245. })
  246. console.log("this.result", this.result);
  247. this.$emit("update", this.result)
  248. },
  249. updateSize(arr) { // 选择尺寸
  250. this.updateSome(arr, 'sizeInfos')
  251. let style = this.result.computedStyle
  252. let sizeArr = ['spacing', 'marginTop', 'marginBottom', 'aroundMargin']
  253. if (this.imgIndex == 2) {
  254. sizeArr = ['marginTop', 'marginBottom']
  255. }
  256. sizeArr.forEach((it, i) => {
  257. style = Object.assign(style, {
  258. [it]: this.sizeInfos[i].value + this.sizeInfos[i].unit
  259. })
  260. })
  261. this.$emit("update", this.result)
  262. },
  263. updateSome(val, name) {
  264. console.log("updateSome", val);
  265. this[name] = val
  266. if (this.result.data[name] && this.result.data[name].length) {
  267. this[name] = this.result.data[name]
  268. } else {
  269. this.result.data[name] = this[name]
  270. }
  271. },
  272. }
  273. });
  274. </script>
  275. <style>
  276. .lucky-btn-text {
  277. margin-top: 15px;
  278. }
  279. .lucky-btn-text-name {
  280. width: 60px;
  281. text-align: right;
  282. padding-right: 8px;
  283. margin-right: 15px;
  284. color: #333;
  285. font-weight: 500;
  286. }
  287. .lucky-btn-text-content {
  288. flex: 1;
  289. }
  290. .pick-goods {
  291. background: #f4f3f7;
  292. border-radius: 4px;
  293. padding: 20px;
  294. }
  295. .pickImgItem {
  296. position: relative;
  297. width: 50px;
  298. height: 50px;
  299. margin: 0 9px 9px 0;
  300. background-color: #ddd;
  301. cursor: pointer;
  302. }
  303. .pickImgItem .el-icon-close {
  304. position: absolute;
  305. top: 0;
  306. right: 0;
  307. font-size: 12px;
  308. }
  309. .add-goods-btn {
  310. border: 1px dashed #6b7685;
  311. line-height: 32px;
  312. height: 32px;
  313. border-radius: 4px;
  314. text-align: center;
  315. cursor: pointer;
  316. }
  317. .clear-diy-style .com-pick-link-content {
  318. width: 100%;
  319. }
  320. </style>