tableSelect.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <div class="select-commodity">
  3. <a class="close" @click="$emit('cancle')">+</a>
  4. <h3 class="title">{{title}}</h3>
  5. <div class="filter">
  6. <div>
  7. <input
  8. type="text"
  9. placeholder="输入关键词"
  10. v-model="key"
  11. @keyup.enter="isClickSearch = !!key, (paging.current = 1) && $emit('updateList',key)">
  12. <i class="iconfont iconsearch" @click="isClickSearch = !!key, (paging.current = 1) && $emit('updateList',key)"></i>
  13. </div>
  14. </div>
  15. <template>
  16. <div class="table-layer">
  17. <table class="list">
  18. <tr>
  19. <th>
  20. <div class="checkbox" v-if="!hideAll">
  21. <input
  22. type="checkbox"
  23. v-model="allSelect"
  24. @click="e => selectAll(e.target)">
  25. <span></span>
  26. </div>
  27. </th>
  28. <th v-for="(item,i) in tabHeaders" :key="i">{{item.name}}</th>
  29. </tr>
  30. <tr v-for="(item,i) in list" :key="i">
  31. <td>
  32. <div class="checkbox">
  33. <input
  34. type="checkbox"
  35. @change="e => selectItem(item, e.target)"
  36. :checked="select.some(i => i[primaryKey] === item[primaryKey])"
  37. >
  38. <span></span>
  39. </div>
  40. </td>
  41. <td v-for="(sub,idx) in tabHeaders" :key="idx">
  42. <div v-if="sub.type=='image'" class="list-img">
  43. <img :src="item[sub.key]" alt="">
  44. </div>
  45. <div class="audio" v-else-if="sub.type=='audio'" >
  46. <v-audio :vkey="item.id" :idleft="`_${$randomWord(true,8,8)}`" :idright="`_${$randomWord(true,8,8)}`" :myAudioUrl="item[sub.key]"></v-audio>
  47. </div>
  48. <span class="shenglvhao" v-else>{{item[sub.key]}}</span>
  49. </td>
  50. </tr>
  51. <tr v-if="list.length === 0">
  52. <td colspan="10">
  53. <div class="nodata">
  54. <img :src="$noresult" alt="">
  55. <span>{{isClickSearch?'未搜索到结果':'暂无素材,快去上传吧'}}</span>
  56. </div>
  57. </td>
  58. </tr>
  59. </table>
  60. </div>
  61. <div class="paging">
  62. <p></p>
  63. <Paging
  64. v-if="paging.total>0"
  65. style="float: right"
  66. :paging="paging"
  67. @changeCurrent="changeCurrent"
  68. />
  69. </div>
  70. </template>
  71. <div class="btns">
  72. <a @click="$emit('cancle')">取消</a>
  73. <a :class="{disable:disable}" @click="$emit('submit', select)" >确定</a>
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. import Paging from './paging'
  79. import vAudio from '@/components/audio'
  80. export default {
  81. props:{
  82. list:{
  83. default(){
  84. return []
  85. },
  86. type:Array
  87. },
  88. tabHeader:{
  89. default(){
  90. return []
  91. },
  92. type:Array
  93. },
  94. paging: {
  95. default:function () {
  96. return {}
  97. },
  98. type: Object
  99. },
  100. selected:{
  101. default(){
  102. return []
  103. },
  104. type:Array
  105. },
  106. title:{
  107. default:'',
  108. type:String
  109. },
  110. current: {
  111. default:''
  112. },
  113. primaryKey: {
  114. default:'id'
  115. },
  116. hideAll:{
  117. type:Boolean,
  118. default:false
  119. }
  120. },
  121. components:{
  122. Paging,
  123. vAudio
  124. },
  125. watch:{
  126. select(){
  127. }
  128. },
  129. computed:{
  130. disable(){
  131. return !this.select.length
  132. },
  133. tabHeaders(){
  134. return this.tabHeader.filter(item=>{
  135. return item.key!='detail'
  136. })
  137. }
  138. },
  139. data () {
  140. return {
  141. categs: [],
  142. isClickSearch:'',
  143. select: [...this.selected],
  144. allSelect: false,
  145. key:'',
  146. tmppaging:{...this.paging}
  147. }
  148. },
  149. methods: {
  150. changeCurrent(data){
  151. this.$emit('changeCurrent',data)
  152. },
  153. selectAll(isSelect) {
  154. this.list.forEach(item => {
  155. this.selectItem(item, isSelect)
  156. })
  157. },
  158. selectItem(item, e) {
  159. let isSelect = e.checked
  160. if (this.hideAll) {
  161. if (item.isUse == '1') {
  162. e.checked = false
  163. return this.$alert({content:'选中素材不能超过600kb'})
  164. }
  165. this.select = [item]
  166. }
  167. else{
  168. let index = this.select.findIndex(i => i[this.primaryKey] === item[this.primaryKey])
  169. if (isSelect) {
  170. !~index && this.select.push(item)
  171. } else {
  172. ~index && this.select.splice(index, 1)
  173. }
  174. }
  175. },
  176. },
  177. mounted() {
  178. this.key = ''
  179. }
  180. }
  181. </script>
  182. <style lang="less" scoped>
  183. ::-webkit-scrollbar-track {
  184. box-shadow: inset 0 0 5px rgb(0 0 0 / 20%);
  185. border-radius: 4px;
  186. background: #fff;
  187. }
  188. .shenglvhao{
  189. text-overflow: ellipsis;
  190. overflow: hidden;
  191. white-space: nowrap;
  192. max-width: 200px;
  193. display: inline-block;
  194. }
  195. .select-commodity {
  196. position: absolute;
  197. z-index: 3;
  198. left: 50%;
  199. top: 50%;
  200. transform: translateX(-50%) translateY(-50%);
  201. color: #202020;
  202. background: #FFFFFF;
  203. max-width: 960px;
  204. width: 100%;
  205. border-radius: 6px;
  206. }
  207. .select-commodity > * {
  208. padding: 15px;
  209. }
  210. .title {
  211. font-size: 16px;
  212. line-height: 20px;
  213. font-weight: 400;
  214. margin: 0;
  215. font-weight: bold;
  216. border-bottom: 1px solid rgba(255,255,255,0.3);
  217. }
  218. .close {
  219. position: absolute;
  220. right: -8px;
  221. top: -15px;
  222. font-size: 25px;
  223. color: #909090;
  224. transform: rotate(45deg);
  225. cursor: pointer;
  226. }
  227. .filter {
  228. padding: 15px;
  229. }
  230. .filter > div {
  231. width: 210px;
  232. height: 34px;
  233. background: rgba(22,26,26,1);
  234. border-radius: 2px;
  235. display: inline-block;
  236. margin-right: 10px;
  237. position: relative;
  238. vertical-align: middle;
  239. }
  240. .filter > div > select,
  241. .filter > div > input {
  242. box-sizing: border-box;
  243. width: 100%;
  244. height: 100%;
  245. border: none;
  246. background: none;
  247. color: #202020;
  248. padding: 8px 10px;
  249. outline: none;
  250. background: #FFFFFF;
  251. border: 1px solid #EBEBEB;
  252. }
  253. .filter > div > input {
  254. padding-right: 40px;
  255. }
  256. .filter > div > i {
  257. position: absolute;
  258. top: 50%;
  259. transform: translateY(-50%);
  260. right: 10px;
  261. cursor: pointer;
  262. color:@color;
  263. }
  264. .scene-layer {
  265. min-height: 400px;
  266. max-height: 60vh;
  267. overflow-y: auto;
  268. position: relative;
  269. .nodata{
  270. position: absolute;
  271. left: 50%;
  272. top: 50%;
  273. transform: translate(-50%,-50%);
  274. }
  275. }
  276. .table-layer {
  277. min-height: 400px;
  278. max-height: 60vh;
  279. overflow-y: auto;
  280. }
  281. .list {
  282. border-collapse: collapse;
  283. width: 100%;
  284. }
  285. .list td,
  286. .list th {
  287. font-size:14px;
  288. line-height:20px;
  289. text-align: center;
  290. padding: 10px 0;
  291. color: #909090;
  292. border-bottom: 1px solid #EBEBEB;
  293. }
  294. .list th {
  295. font-weight: bold;
  296. color: #202020;
  297. }
  298. .list-img {
  299. height: 40px;
  300. line-height: 40px;
  301. position: relative;
  302. }
  303. .list-img > img {
  304. width: 40px;
  305. height: 40px;
  306. }
  307. .checkbox {
  308. position: relative;
  309. width:14px;
  310. height:14px;
  311. border-radius:2px;
  312. }
  313. .checkbox > input,
  314. .checkbox > span {
  315. width: 100%;
  316. height: 100%;
  317. position: absolute;
  318. left: 0;
  319. top: 0;
  320. }
  321. .checkbox > input {
  322. z-index: 1;
  323. opacity: 0;
  324. cursor: pointer;
  325. }
  326. .checkbox > span {
  327. z-index: 2;
  328. background:#fff;
  329. border:1px solid #ccc;
  330. pointer-events: none;
  331. }
  332. .checkbox > input:checked + span {
  333. background:#fff;
  334. border:1px solid rgba(0,200,175,1);
  335. background:#00C8AF url(/static/img/g.png) no-repeat center center;
  336. }
  337. .checkbox > input:disabled {
  338. cursor: not-allowed;
  339. }
  340. .checkbox > input:disabled + span {
  341. background:#CCCCCC;
  342. background:rgba(0,200,175,0.3) no-repeat center center;
  343. }
  344. .paging {
  345. display: flex;
  346. align-items: center;
  347. justify-content: space-between;
  348. p {
  349. font-size: 12px;
  350. }
  351. }
  352. .btns {
  353. text-align: center;
  354. > a {
  355. width:120px;
  356. height:40px;
  357. text-align: center;
  358. line-height: 40px;
  359. opacity:1;
  360. border-radius:20px;
  361. font-size:12px;
  362. cursor: pointer;
  363. display: inline-block;
  364. color: #00C8AF;
  365. margin: 0 10px;
  366. &:nth-child(2) {
  367. background-color: #00C8AF;
  368. color: #fff;
  369. }
  370. &:nth-child(1) {
  371. border:1px solid #00C8AF;
  372. }
  373. }
  374. .disable{
  375. pointer-events: none!important;
  376. opacity: 0.5!important;
  377. }
  378. }
  379. </style>