style.php 14 KB

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