relay-banner-simple.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template id="relay-banner-simple">
  2. <div class="relay-banner-simple">
  3. <div class="diy-component-edit">
  4. <el-form @submit.native.prevent label-width="100px">
  5. <el-form-item label="样式">
  6. <div flex="dir:left">
  7. <div @click="data.style=1" v-if="styleData.indexOf(1) != '-1'" class="banner-style-item" :class="data.style==1?'active':''">
  8. <div class="banner-style-1"></div>
  9. <div>样式1</div>
  10. </div>
  11. <div @click="data.style=2" v-if="styleData.indexOf(2) != '-1'" class="banner-style-item" :class="data.style==2?'active':''">
  12. <div class="banner-style-2" flex>
  13. <div></div>
  14. <div></div>
  15. </div>
  16. <div>样式2</div>
  17. </div>
  18. </div>
  19. </el-form-item>
  20. <!-- <el-form-item label="填充方式">
  21. <el-radio v-model="data.fill" :label="0">留白</el-radio>
  22. <el-radio v-model="data.fill" :label="1">填充</el-radio>
  23. </el-form-item> -->
  24. <el-form-item label="高度">
  25. <el-input size="small" v-model.number="data.height" min="10" type="number">
  26. <template slot="append">px</template>
  27. </el-input>
  28. </el-form-item>
  29. <el-form-item label="轮播图">
  30. <div class="banner-edit-item" v-for="(banner,index) in data.banners">
  31. <div class="banner-edit-options">
  32. <el-button @click="bannerItemDelete(index)" type="primary" icon="el-icon-delete"
  33. style="top: -6px;right: -31px;"></el-button>
  34. </div>
  35. <div flex="box:first">
  36. <div>
  37. <com-image-upload width="750" :height="data.height" v-model="banner.picUrl"
  38. style="margin-right: 5px;"></com-image-upload>
  39. </div>
  40. <!-- <div class="chooseLink">-->
  41. <!-- <div @click="pickLinkClick(index)">-->
  42. <!-- <el-input v-model="banner.url" placeholder="点击选择链接" readonly size="small"></el-input>-->
  43. <!-- <el-button type="primary" size="small" @click="showDialog">选择活动</el-button>-->
  44. <!-- </div>-->
  45. <!-- </div>-->
  46. </div>
  47. </div>
  48. <el-button size="small" @click="addBanner">添加轮播图</el-button>
  49. </el-form-item>
  50. </el-form>
  51. </div>
  52. <div class="diy-component-preview" v-if="componentPreview">
  53. <div class="banner-container" :style="cContainerStyle">
  54. <el-carousel :height="data.height+'px'" :type="data.style==2?'card':''">
  55. <el-carousel-item v-for="(banner,index) in data.banners" :key="index">
  56. <div :class="'banner-img '+cBannerImgClass"
  57. :style="'background-image: url('+banner.picUrl+');'"></div>
  58. </el-carousel-item>
  59. </el-carousel>
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. Vue.component('relay-banner-simple', {
  66. template: '#relay-banner-simple',
  67. props: {
  68. value: Object,
  69. },
  70. data() {
  71. return {
  72. componentPreview: false,
  73. currentBannerIndex: null,
  74. data: {
  75. style: 1,
  76. fill: 1,
  77. height: 450,
  78. banners: [],
  79. },
  80. //样式控制数组
  81. styleData: [1, 2],
  82. dialogTableVisible: false,
  83. page: 1,
  84. pageCount: 0,
  85. bannerList: [],
  86. listLoading: false,
  87. multipleSelection: [],
  88. //弹框配置
  89. form: {
  90. diy: 1,
  91. keyword: '',
  92. limit: 10,
  93. },
  94. relayList : [],
  95. listLoading2:false,
  96. dialogVisible:false,
  97. radioSelection:false,
  98. selectRelay:{},
  99. relayPageCount: 0,
  100. relayCurrentPage: 0,
  101. };
  102. },
  103. created() {
  104. if (!this.value) {
  105. this.$emit('input', JSON.parse(JSON.stringify(this.data)));
  106. } else {
  107. this.data = JSON.parse(JSON.stringify(this.value));
  108. }
  109. },
  110. computed: {
  111. cContainerStyle() {
  112. return `height:${this.data.height}px;`;
  113. },
  114. cBannerImgClass() {
  115. if (this.data.fill == 0) {
  116. return 'banner-img-contain';
  117. }
  118. if (this.data.fill == 1) {
  119. return 'banner-img-cover';
  120. }
  121. },
  122. },
  123. watch: {
  124. data: {
  125. deep: true,
  126. handler(newVal, oldVal) {
  127. this.$emit('input', newVal, oldVal)
  128. },
  129. },
  130. value: {
  131. deep: true,
  132. handler(newVal, oldVal) {
  133. this.data = newVal;
  134. if(newVal.showStyleData){
  135. this.styleData = newVal.showStyleData;
  136. }
  137. },
  138. },
  139. },
  140. methods: {
  141. addBanner() {
  142. this.data.banners.push({
  143. picUrl: '',
  144. url: '',
  145. openType: '',
  146. });
  147. },
  148. bannerItemDelete(index) {
  149. this.data.banners.splice(index, 1);
  150. },
  151. pickLinkClick(index) {
  152. this.currentBannerIndex = index;
  153. },
  154. linkSelected(list) {
  155. if (!list.length) {
  156. return;
  157. }
  158. const link = list[0];
  159. if (this.currentBannerIndex !== null) {
  160. this.data.banners[this.currentBannerIndex].openType = link.open_type;
  161. this.data.banners[this.currentBannerIndex].url = link.new_link_url;
  162. this.data.banners[this.currentBannerIndex].params = link.params ? link.params : [];
  163. this.currentBannerIndex = null;
  164. }
  165. },
  166. handleSelectionChange(val) {
  167. let arr = [];
  168. val.forEach(function (item, index) {
  169. arr.push({
  170. picUrl: item.pic_url,
  171. openType: item.open_type,
  172. url: item.page_url,
  173. params: item.params
  174. })
  175. });
  176. this.multipleSelection = arr;
  177. },
  178. updateBanner() {
  179. console.log(this.multipleSelection)
  180. let self = this;
  181. self.multipleSelection.forEach(function (item, index) {
  182. self.data.banners.push(item)
  183. });
  184. self.dialogTableVisible = false;
  185. },
  186. //显示弹框
  187. showDialog(){
  188. this.dialogVisible = true;
  189. this.radioSelection = 0;
  190. this.getRelayList();
  191. },
  192. getRelayList(){
  193. this.listLoading2 = true;
  194. request({
  195. params: {
  196. r: 'plugin/relay/mall/relay/get-list',
  197. ...this.form
  198. },
  199. method: 'get',
  200. }).then(res => {
  201. if (res.data.code == 0) {
  202. var data = res.data.data;
  203. this.relayList = data.list;
  204. this.relayPageCount = data.pagData.page_count;
  205. this.relayCurrentPage = data.pagData.current_page;
  206. }
  207. this.listLoading2 = false;
  208. }).catch(e => {
  209. this.listLoading2 = false;
  210. });
  211. },
  212. //分页
  213. pagination(currentPage) {
  214. this.form.page = currentPage;
  215. this.getRelayList();
  216. },
  217. selectionChange(e){
  218. this.selectRelay = e;
  219. },
  220. cancelSelect(){
  221. this.selectRelay = null;
  222. this.dialogVisible = false;
  223. },
  224. confirmSelectRelay(){
  225. this.dialogVisible = false;
  226. if (this.currentBannerIndex !== null) {
  227. this.data.banners[this.currentBannerIndex].openType = '';
  228. this.data.banners[this.currentBannerIndex].url = '/mch/Solitaire/details/details?relayId=' + this.selectRelay.id;
  229. this.data.banners[this.currentBannerIndex].params = [];
  230. this.currentBannerIndex = null;
  231. }
  232. },
  233. searchFun(){
  234. this.getRelayList();
  235. },
  236. reset() {
  237. this.form = {};
  238. this.getRelayList();
  239. },
  240. }
  241. });
  242. </script>
  243. <style>
  244. .el-input--small{
  245. width: 75%!important;
  246. }
  247. .relay-banner-simple .diy-component-edit {
  248. width: 600px;
  249. float: left;
  250. margin: 0 20px;
  251. }
  252. .relay-banner-simple .diy-component-preview {
  253. width: 400px;
  254. float: left;
  255. margin: 0 30px;
  256. border: 1px #00a0e9 dashed;
  257. padding: 10px 10px 25px 10px;
  258. }
  259. .relay-banner-simple .banner-container {
  260. background: #fff;
  261. }
  262. .relay-banner-simple .banner-container .banner-img {
  263. height: 100%;
  264. width: 100%;
  265. background-repeat: no-repeat;
  266. background-position: center;
  267. }
  268. .relay-banner-simple .banner-container .banner-img-cover {
  269. background-size: cover;
  270. }
  271. .relay-banner-simple .banner-container .banner-img-contain {
  272. background-size: contain;
  273. }
  274. .relay-banner-simple .banner-edit-item {
  275. border: 1px solid #dcdfe6;
  276. padding: 5px;
  277. margin-bottom: 5px;
  278. }
  279. .relay-banner-simple .pic-upload {
  280. display: block;
  281. width: 65px;
  282. height: 65px;
  283. line-height: 65px;
  284. border: 1px dashed #8bc4ff;
  285. color: #8bc4ff;
  286. background: #f9f9f9;
  287. cursor: pointer;
  288. background-size: 100% 100%;
  289. font-size: 28px;
  290. text-align: center;
  291. vertical-align: middle;
  292. }
  293. .relay-banner-simple .banner-edit-options {
  294. position: relative;
  295. }
  296. .relay-banner-simple .banner-edit-options .el-button {
  297. height: 25px;
  298. line-height: 25px;
  299. width: 25px;
  300. padding: 0;
  301. text-align: center;
  302. border: none;
  303. border-radius: 0;
  304. position: absolute;
  305. margin-left: 0;
  306. }
  307. .relay-banner-simple .banner-style-item {
  308. width: 100px;
  309. border: 1px solid #ebeef5;
  310. cursor: pointer;
  311. padding: 5px;
  312. line-height: normal;
  313. text-align: center;
  314. color: #606266;
  315. }
  316. .relay-banner-simple .banner-style-item + .banner-style-item {
  317. margin-left: 5px;
  318. }
  319. .relay-banner-simple .banner-style-item.active {
  320. border-color: #00a0e9;
  321. color: #409EFF;
  322. }
  323. .relay-banner-simple .banner-style-1,
  324. .relay-banner-simple .banner-style-2 {
  325. display: block;
  326. height: 50px;
  327. margin: 0 auto 5px;
  328. position: relative;
  329. }
  330. .relay-banner-simple .banner-style-1 {
  331. background: #e6f4ff;
  332. }
  333. .relay-banner-simple .banner-style-2 > div {
  334. background: #e6f4ff;
  335. position: absolute;
  336. left: 0;
  337. top: 10%;
  338. height: 50px;
  339. width: 100%;
  340. z-index: 0;
  341. zoom: .75;
  342. }
  343. .relay-banner-simple .banner-style-2 > div:last-child {
  344. left: 15%;
  345. zoom: 1;
  346. box-shadow: 0 0 5px rgba(0, 0, 0, .2);
  347. z-index: 1;
  348. width: 70%;
  349. top: 0;
  350. }
  351. .chooseLink .el-input-group__append {
  352. background-color: #fff;
  353. }
  354. </style>