diy-style.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!-- 风格组件 -->
  2. <template id="diy-style">
  3. <diy-style-contain class="diy-style" :title="topName">
  4. <div class="diy-style-exhibit" flex="main:center cross:center">
  5. <el-image class="exhibit-img" :style="{...imgStyle}" :src="imgUrl + imgInfo[selIndex].img" fit="fill"></el-image>
  6. <div class="diy-update-style" @click="stylePop = true">
  7. 修改风格
  8. </div>
  9. </div>
  10. <el-dialog :title="topName" :visible.sync="stylePop" width="66%" :modal-append-to-body="false">
  11. <div flex="wrap:wrap" class="diy-style-info">
  12. <div :style="{width: (100/count) + '%'}" v-for="(item,index) in imgInfo" :key="index">
  13. <div class="diy-style-img" :class="{'diy-style-sel-img': index==selIndex}">
  14. <el-image :style="{'height': imgStyle.height}" style="width: 100%;" @click="selStyleImg(index)" :src="imgUrl + item.img" fit="fill"></el-image>
  15. <i v-show="index==selIndex" class="el-icon-success diy-style-icon"></i>
  16. </div>
  17. <div class="diy-style-text">{{item.text}}</div>
  18. </div>
  19. </div>
  20. <div class="diy-style-bottom">
  21. <el-button size="mini" @click="stylePop = false" plain>取消</el-button>
  22. <el-button size="mini" @click="saveStyle" type="primary">确定</el-button>
  23. </div>
  24. </el-dialog>
  25. </diy-style-contain>
  26. </template>
  27. <script>
  28. Vue.component('diy-style', {
  29. template: '#diy-style',
  30. name: 'diy-style',
  31. props: {
  32. topName: { //头部标题
  33. type: String,
  34. default: "选择风格",
  35. },
  36. imgStyle: { //图片样式
  37. type: Object,
  38. default: () => {
  39. return {
  40. width: '206px',
  41. height: 'auto'
  42. }
  43. }
  44. },
  45. count: { //每格多少个
  46. type: [String, Number],
  47. default: 4,
  48. },
  49. imgUrl: { //图片路径开头
  50. type: String,
  51. default: "<?=Yii::getAlias('@attachurl')?>"
  52. },
  53. defIndex: {
  54. type: Number,
  55. default: 0
  56. },
  57. /*
  58. 数据结构
  59. {
  60. img: "", //图片路径
  61. text: "", //展示文本
  62. }
  63. */
  64. imgInfo: {
  65. type: Array,
  66. default: () => {
  67. return []
  68. }
  69. }
  70. },
  71. data() {
  72. return {
  73. stylePop: false,
  74. selIndex: 0,
  75. }
  76. },
  77. created() {
  78. this.selIndex = this.defIndex;
  79. },
  80. methods: {
  81. selStyleImg(index) {
  82. this.selIndex = index;
  83. },
  84. saveStyle() {
  85. const item = this.imgInfo[this.selIndex]
  86. this.$emit("chang", this.selIndex, item);
  87. this.stylePop = false;
  88. }
  89. }
  90. })
  91. </script>
  92. <style>
  93. .diy-style-exhibit {
  94. background: #F4F3F7;
  95. height: 184px;
  96. position: relative;
  97. }
  98. .diy-update-style {
  99. position: absolute;
  100. bottom: 0;
  101. left: 0;
  102. width: 100%;
  103. height: 35px;
  104. line-height: 35px;
  105. text-align: center;
  106. background: rgba(102, 102, 102, 0.72);
  107. font-weight: bold;
  108. font-size: 14px;
  109. color: rgba(255, 255, 255, 0.82);
  110. }
  111. .diy-update-style,
  112. .diy-style-img:hover {
  113. cursor: pointer
  114. }
  115. .diy-style .el-dialog__header {
  116. border-bottom: 1px solid #f2f2f2;
  117. padding: 12px 22px;
  118. }
  119. .diy-style .el-dialog__body {
  120. padding: 0;
  121. }
  122. .diy-style .diy-style-bottom {
  123. border-top: 1px solid #f2f2f2;
  124. padding: 10px 20px;
  125. text-align: end;
  126. }
  127. .diy-style-info {
  128. padding: 16px;
  129. }
  130. .diy-style-img {
  131. background: #f7f8fa;
  132. border: 1px solid #ededed;
  133. width: 95%;
  134. position: relative;
  135. font-size: 0;
  136. }
  137. .diy-style-sel-img {
  138. border: 1px solid #3892F1;
  139. }
  140. .diy-style-icon {
  141. position: absolute;
  142. font-size: 16px;
  143. bottom: -8px;
  144. right: -8px;
  145. background: #FFF;
  146. border-radius: 50%;
  147. color: #2D8CF0;
  148. }
  149. .diy-style-text {
  150. width: 95%;
  151. text-align: center;
  152. margin-bottom: 10px;
  153. margin-top: 10px;
  154. }
  155. </style>