style.php 16 KB

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