style.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template id="group-goods-style">
  2. <div class="group-goods-style">
  3. <!-- 公共 -->
  4. <diy-style class="style-goods fill-border-top" :img-info="imgInfo" :def-index="imgIndex" :img-style="{ width: '206px', height: 'auto' }" @chang="upImgIndex"></diy-style>
  5. <diy-style-contain title="标题" class="clear-diy-style fill-border-top">
  6. <el-radio-group v-model="titleRadio" @change="titleChange">
  7. <el-radio :label="0">隐藏</el-radio>
  8. <el-radio :label="1">显示</el-radio>
  9. </el-radio-group>
  10. <div style="padding-top: 10px" v-if="titleRadio == 1">
  11. <diy-operation-list v-model="titleList" :label-width="50" @on-change="onChange"></diy-operation-list>
  12. </div>
  13. </diy-style-contain>
  14. <diy-style-contain title="选择商品" class="clear-diy-style fill-border-top">
  15. <div class="pick-goods">
  16. <com-pick-link @selected="selectNavUrl" :pick-type="pickType" :default-select-list="selectList" :default-tabs="[{name: 'marketing',children:['group_activity'] }]">
  17. <div class="add-goods-btn">+添加({{ pickImgList.length + '/' + maxGroupLen }})</div>
  18. </com-pick-link>
  19. <div flex="cross:center" style="margin-top: 20px;flex-wrap:wrap" v-if="pickImgList.length">
  20. <div class="pickImgItem" v-for="(item,index) in pickImgList" :key="index" @mouseenter="mouseenter(index)" @mouseleave="mouseleave(index)">
  21. <el-image style="width: 50px; height: 50px" :src="item.params.img" fit="contain"></el-image>
  22. <div v-show="index == pickIndex || item.visible">
  23. <el-popover placement="bottom" v-model="item.visible">
  24. <p class="diy-del-text">确定删除吗?</p>
  25. <div flex="cross:center">
  26. <el-button class="diy-del-btn" size="mini" plain @click="delModel(index)">删除</el-button>
  27. <el-button size="mini" plain @click="item.visible = false">取消</el-button>
  28. </div>
  29. <i class="el-icon-close" slot="reference" style="color:#999;"></i>
  30. </el-popover>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </diy-style-contain>
  36. <diy-tabs title="组件样式" class="fill-border-top" radio_text='text' :default_item="defaultForm.tabItem" @change="colorSelect"></diy-tabs>
  37. <diy-color class="fill-border-top" :color-infos="colorInfos" :str-color="defColor" @chang="updateColor"></diy-color>
  38. <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>
  39. <diy-size-setting class="fill-border-top" top-name="圆角设置" :size-infos="defaultForm.radiusInfos" :max-value="20" @chang="RadiusChange"></diy-size-setting>
  40. </div>
  41. </template>
  42. <script>
  43. Vue.component('group-goods-style', {
  44. name: "group-goods-style",
  45. mixins: [basicMixins],
  46. template: '#group-goods-style',
  47. props: {
  48. activeItem: {
  49. type: Object,
  50. default () {
  51. return {}
  52. }
  53. }
  54. },
  55. data() {
  56. return {
  57. maxGroupLen: 30,
  58. titleRadio: 0,
  59. titleList: [{
  60. type: 'input',
  61. label: "文字",
  62. value: '商品拼团',
  63. max: 6,
  64. showLimit: true,
  65. setKey: "title",
  66. }, {
  67. type: "size",
  68. label: "上边距",
  69. value: 10,
  70. setKey: "paddingTop",
  71. maxValue: 20,
  72. }, {
  73. type: "size",
  74. label: "下边距",
  75. value: 10,
  76. setKey: "paddingBottom",
  77. maxValue: 20,
  78. }, ],
  79. imgInfo: [{
  80. img: "group-goods/group-style1.png",
  81. text: "风格1",
  82. type: 1
  83. }, {
  84. img: "group-goods/group-style2.png",
  85. text: "风格2",
  86. type: 2
  87. }, {
  88. img: "group-goods/group-style3.png",
  89. text: "风格3",
  90. type: 3
  91. }],
  92. imgIndex: 0,
  93. colorInfos: ['背景色', '按钮文字', '按钮背景'],
  94. defColor: ['transparent', '#fff', '#db0505'],
  95. sizeInfos: ['商品间距', '上边距', '下边距', '左右边距'],
  96. sizeInfosValue: [5, 0, 0, 0],
  97. sizeInfosMax: [50, 50, 50, 20],
  98. chooseGoods: 1,
  99. // 选择商品
  100. pickType: ['group_activity'],
  101. pickIndex: -1,
  102. pickImgList: [],
  103. selectUrl: '',
  104. showLineList: [{
  105. type: "size",
  106. label: "显示条数",
  107. value: 10,
  108. unit: "个",
  109. maxValue: 20
  110. }, ],
  111. selectList: [],
  112. }
  113. },
  114. methods: {
  115. init() {
  116. basicMixins.methods.init.call(this); // 以前的数据调用一下
  117. this.titleRadio = this.result.data.titleRadio || 0
  118. // 标题风格
  119. if (this.result.data.groupStyle) {
  120. this.imgIndex = this.imgInfo.findIndex(item => (item.type === this.result.data.groupStyle.type))
  121. }
  122. this.chooseGoods = this.result.data.chooseGoods || 1
  123. // 选择商品
  124. let arr = ['data', 'goods']
  125. this.pickImgList = getObjValue(this.result, arr, [])
  126. // this.getSelectList(this.pickImgList)
  127. let commCate = ['data', 'commCate', 'title']
  128. this.selectUrl = getObjValue(this.result, commCate, '')
  129. this.initList('titleList')
  130. },
  131. titleChange(e) {
  132. this.result.data.titleRadio = e
  133. this.$emit("update", this.result)
  134. },
  135. upImgIndex(index, item) {
  136. this.imgIndex = index;
  137. if (index == 0 || index == 2) {
  138. this.colorInfos = [{
  139. color: "transparent",
  140. name: "背景色",
  141. showAlpha: false,
  142. value: "transparent",
  143. },
  144. {
  145. color: "#fff",
  146. name: "按钮文字",
  147. showAlpha: false,
  148. value: "#fff"
  149. },
  150. {
  151. color: "#db0505",
  152. name: "按钮背景",
  153. showAlpha: false,
  154. value: "#db0505"
  155. }
  156. ]
  157. } else {
  158. this.colorInfos = [{
  159. color: "transparent",
  160. name: "背景色",
  161. showAlpha: false,
  162. value: "transparent",
  163. }]
  164. }
  165. if (index == 0 || index == 1) {
  166. this.sizeInfos = [{
  167. disabled: false,
  168. hidden: false,
  169. maxValue: 50,
  170. name: "商品间距",
  171. unit: "px",
  172. value: 5
  173. },
  174. {
  175. disabled: false,
  176. hidden: false,
  177. maxValue: 50,
  178. name: "上边距",
  179. unit: "px",
  180. value: 0
  181. },
  182. {
  183. disabled: false,
  184. hidden: false,
  185. maxValue: 50,
  186. name: "下边距",
  187. unit: "px",
  188. value: 0
  189. },
  190. {
  191. disabled: false,
  192. hidden: false,
  193. maxValue: 20,
  194. name: "左右边距",
  195. unit: "px",
  196. value: 0
  197. }
  198. ]
  199. } else {
  200. this.sizeInfos = [{
  201. disabled: false,
  202. hidden: false,
  203. maxValue: 50,
  204. name: "上边距",
  205. unit: "px",
  206. value: 0
  207. },
  208. {
  209. disabled: false,
  210. hidden: false,
  211. maxValue: 50,
  212. name: "下边距",
  213. unit: "px",
  214. value: 0
  215. },
  216. ]
  217. this.result.computedStyle.spacing = 0
  218. }
  219. this.result.data.colorInfos = this.colorInfos
  220. this.result.data.sizeInfos = this.sizeInfos
  221. this.result.data.groupStyle = item;
  222. this.updateColor(this.colorInfos)
  223. this.updateSize(this.sizeInfos)
  224. },
  225. updateColor(arr) { // 选择颜色
  226. this.updateSome(arr, 'colorInfos')
  227. let style = this.result.computedStyle
  228. let colorArr = ['bgColor', 'btnTextColor', 'btnBackground']
  229. if (this.imgIndex == 1) {
  230. colorArr = ['bgColor']
  231. }
  232. colorArr.forEach((it, i) => {
  233. style = Object.assign(style, {
  234. [it]: this.colorInfos[i].color
  235. })
  236. })
  237. this.$emit("update", this.result)
  238. },
  239. updateSize(arr) { // 选择尺寸
  240. this.updateSome(arr, 'sizeInfos')
  241. let style = this.result.computedStyle
  242. let sizeArr = ['spacing', 'marginTop', 'marginBottom', 'aroundMargin']
  243. if (this.imgIndex == 2) {
  244. sizeArr = ['marginTop', 'marginBottom']
  245. }
  246. sizeArr.forEach((it, i) => {
  247. style = Object.assign(style, {
  248. [it]: this.sizeInfos[i].value + this.sizeInfos[i].unit
  249. })
  250. })
  251. this.$emit("update", this.result)
  252. },
  253. updateSome(val, name) {
  254. this[name] = val
  255. if (this.result.data[name] && this.result.data[name].length) {
  256. this[name] = this.result.data[name]
  257. } else {
  258. this.result.data[name] = this[name]
  259. }
  260. },
  261. mouseenter(index) {
  262. this.pickIndex = index
  263. },
  264. mouseleave() {
  265. this.pickIndex = -1
  266. },
  267. selectNavUrl(e) {
  268. this.pickImgList.push(...e)
  269. if (this.pickImgList.length > this.maxGroupLen) {
  270. this.$message({
  271. message: `最多添加${this.maxGroupLen}件商品噢`,
  272. type: 'warning'
  273. });
  274. }
  275. this.pickImgList = this.pickImgList.slice(0, this.maxGroupLen)
  276. this.result.data.goods = this.pickImgList
  277. this.$emit("update", this.result)
  278. },
  279. getSelectList(arr) {
  280. if (arr.length == 0) return;
  281. this.selectList = []
  282. arr.forEach(item => {
  283. this.selectList.push(item.params.id)
  284. })
  285. console.log(this.selectList, '-----------this.selectList')
  286. },
  287. selectedUrl(value) {
  288. var item = getObjValue(value[0], ["params"], {})
  289. this.selectUrl = item.title
  290. this.showLineList[0].value = 10
  291. this.updateSome(Object.assign({
  292. count: 10
  293. }, item), 'commCate')
  294. },
  295. delModel(index) {
  296. // let arr = []
  297. // this.pickImgList.forEach((it, i) => {
  298. // if (i == index) {
  299. // arr.push(it)
  300. // }
  301. // })
  302. this.pickImgList.splice(index, 1)
  303. this.result.data.goods = this.pickImgList
  304. // this.getSelectList(this.pickImgList)
  305. this.$emit("update", this.result)
  306. },
  307. onChange(e) {
  308. this.updataList('titleList')
  309. },
  310. updataList(target) {
  311. this[target].map((item, index) => {
  312. var obj = {}
  313. if (item.setKey) {
  314. const key = item.setKey
  315. console.log(key, item.value)
  316. this.updateStyle(key, item.value)
  317. }
  318. return obj
  319. })
  320. },
  321. updateStyle(key, value) {
  322. var obj = this.result.data
  323. this.result.data = Object.assign(obj, {
  324. [key]: value
  325. })
  326. console.log(this.result.data)
  327. this.$emit("update", this.result)
  328. },
  329. initList(target) {
  330. var data = this.result.data
  331. if (this[target] && !this[target].length) {
  332. return false
  333. }
  334. var arr = this[target].map(item => {
  335. var obj = Object.assign(item, {
  336. value: item.value
  337. })
  338. if ((item.setKey in data) && data[item.setKey] !== "") {
  339. obj.value = data[item.setKey]
  340. }
  341. return obj
  342. });
  343. this[target] = arr
  344. },
  345. }
  346. });
  347. </script>
  348. <style>
  349. .style-goods .exhibit-img {
  350. width: 190px !important;
  351. height: 186px !important;
  352. }
  353. .group-goods-style .tabs-com .el-radio-button__inner {
  354. padding: 5px 0;
  355. }
  356. .pick-goods {
  357. background: #f4f3f7;
  358. border-radius: 4px;
  359. padding: 20px;
  360. }
  361. .pickImgItem {
  362. position: relative;
  363. width: 50px;
  364. height: 50px;
  365. margin: 0 9px 9px 0;
  366. background-color: #ddd;
  367. cursor: pointer;
  368. }
  369. .pickImgItem .el-icon-close {
  370. position: absolute;
  371. top: 0;
  372. right: 0;
  373. font-size: 12px;
  374. }
  375. .add-goods-btn {
  376. border: 1px dashed #6b7685;
  377. line-height: 32px;
  378. height: 32px;
  379. border-radius: 4px;
  380. text-align: center;
  381. cursor: pointer;
  382. }
  383. .clear-diy-style .com-pick-link-content {
  384. width: 100%;
  385. }
  386. .title-input {
  387. padding: 10px 0;
  388. }
  389. </style>