SelectPoster.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <script>
  2. import { getTree, getList } from '@/api/material'
  3. export default {
  4. name: 'SelectTag',
  5. components: {},
  6. props: {
  7. // 添加标签显隐
  8. visible: {
  9. type: Boolean,
  10. default: false
  11. },
  12. title: {
  13. type: String,
  14. default: '选择海报'
  15. },
  16. selected: {
  17. type: Array,
  18. default: () => []
  19. },
  20. type: {
  21. type: String,
  22. default: 'add'
  23. }
  24. },
  25. data() {
  26. return {
  27. list: [],
  28. total: 0,
  29. listOneArray: [],
  30. selectedGroup: '',
  31. removeTag: [],
  32. Pselected: this.selected,
  33. treeData: [],
  34. attrProps: { value: 'id', label: 'name' },
  35. posterRequestParams: {
  36. mediaType: 5,
  37. pageNum: 1,
  38. pageSize: 10,
  39. categoryId: '',
  40. search: '',
  41. status: 0 // 0 启用 1 不启用
  42. },
  43. selectPoster: {}
  44. }
  45. },
  46. watch: {
  47. type(val) {
  48. val === 'remove' && (this.removeTag = this.selected.slice())
  49. },
  50. selectGroup(value) {
  51. console.log(value)
  52. }
  53. },
  54. computed: {
  55. Pvisible: {
  56. get() {
  57. // this.getTree();
  58. return this.visible
  59. },
  60. set(val) {
  61. this.$emit('update:visible', val)
  62. }
  63. },
  64. page() {
  65. return Math.ceil(this.total / 10)
  66. }
  67. },
  68. created() {
  69. // this.type === 'remove' && (this.removeTag = this.Pselected.slice())
  70. this.getList(this.posterRequestParams)
  71. this.getTree()
  72. },
  73. mounted() {},
  74. methods: {
  75. // 获取类目树
  76. getTree() {
  77. getTree(5).then(({ data }) => {
  78. this.treeData = data
  79. })
  80. },
  81. // 获取素材列表
  82. getList(params) {
  83. this.loading = true
  84. getList(params)
  85. .then(({ rows, total }) => {
  86. this.list = rows
  87. this.total = +total
  88. this.loading = false
  89. })
  90. .catch(() => {
  91. this.loading = false
  92. })
  93. },
  94. selectGroup(value) {
  95. this.posterRequestParams.categoryId = value[value.length - 1]
  96. this.getList(this.posterRequestParams)
  97. },
  98. selctPoster(value) {
  99. this.selectPoster = value
  100. },
  101. decrease() {
  102. if (this.posterRequestParams.pageNum > 1) {
  103. this.posterRequestParams.pageNum -= 1
  104. this.getList(this.posterRequestParams)
  105. }
  106. },
  107. Increase() {
  108. if (Math.ceil(this.total / 10) > this.posterRequestParams.pageNum) {
  109. this.posterRequestParams.pageNum += 1
  110. this.getList(this.posterRequestParams)
  111. }
  112. },
  113. submit() {
  114. this.Pvisible = false
  115. this.$emit('success', this.selectPoster)
  116. }
  117. }
  118. }
  119. </script>
  120. <template>
  121. <el-dialog :title="title" :visible.sync="Pvisible" :close-on-click-modal="false">
  122. <div>
  123. <div class="selectPosterGroup">
  124. <div>
  125. <span class="mr20">选择分组</span>
  126. <el-cascader :options="treeData" :props="attrProps" @change="selectGroup" clearable>
  127. </el-cascader>
  128. </div>
  129. <div class="selectPage">
  130. <span
  131. ><i class="el-icon-arrow-left" @click="decrease"></i>1/{{ page
  132. }}<i class="el-icon-arrow-right" @click="Increase"></i
  133. ></span>
  134. </div>
  135. </div>
  136. <div class="mt20">
  137. <div class="posterBody" v-for="item in list" :key="item.id" @click="selctPoster(item)">
  138. <img :src="item.materialUrl" />
  139. <div class="materialName">{{ item.materialName }}</div>
  140. <div class="materialMask" v-if="item.id === selectPoster.id">
  141. <i class="el-icon-success"></i>
  142. </div>
  143. </div>
  144. </div>
  145. <slot></slot>
  146. </div>
  147. <div slot="footer">
  148. <el-button @click="Pvisible = false">取 消</el-button>
  149. <el-button type="primary" @click="submit">确 定</el-button>
  150. </div>
  151. </el-dialog>
  152. </template>
  153. <style lang="scss" scoped>
  154. .user-list {
  155. .el-row {
  156. line-height: 26px;
  157. }
  158. }
  159. .selectPage {
  160. i {
  161. cursor: pointer;
  162. }
  163. }
  164. .mt20 {
  165. display: flex;
  166. flex-wrap: wrap;
  167. justify-content: space-between;
  168. .posterBody {
  169. width: 30%;
  170. border: 1px solid #000;
  171. margin-bottom: 10px;
  172. cursor: pointer;
  173. position: relative;
  174. }
  175. img {
  176. width: 100%;
  177. }
  178. .materialName {
  179. height: 40px;
  180. font-size: 14px;
  181. line-height: 40px;
  182. padding-left: 20px;
  183. border-top: 1px solid #000;
  184. }
  185. .materialMask {
  186. position: absolute;
  187. left: 0;
  188. top: 0;
  189. height: 100%;
  190. width: 100%;
  191. z-index: 99;
  192. background: rgba(0, 0, 0, 0.6);
  193. display: flex;
  194. align-items: center;
  195. justify-content: center;
  196. i {
  197. font-size: 24px;
  198. color: #4185f4;
  199. z-index: 888;
  200. }
  201. }
  202. }
  203. .selectPosterGroup {
  204. display: flex;
  205. justify-content: space-between;
  206. }
  207. </style>