advertmaterial.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <div>
  3. <div class="container">
  4. <div class="container-box">
  5. <h2>素材库</h2>
  6. <div class="adv-type">
  7. <div class="search-list-box">
  8. <el-select v-model="infotype" @change="changeType" class="search-box">
  9. <el-option v-for="items in typeList" :key="items.dataCode" :label="items.dataName"
  10. :value="items.dataCode">
  11. </el-option>
  12. </el-select>
  13. <el-input v-model="fileNameSearch" placeholder="文件名称" @input="searchInput" class="file-name-search search-box"></el-input>
  14. <el-select v-model="timeSort" @change="timeSortChange" class="search-box">
  15. <el-option v-for="item in sortList" :key="item.sortCode" :label="item.sortName"
  16. :value="item.sortCode">
  17. </el-option>
  18. </el-select>
  19. <div class="block search-box search-box1">
  20. <el-date-picker
  21. v-model="dateSearch"
  22. type="daterange"
  23. range-separator="至"
  24. start-placeholder="开始日期"
  25. end-placeholder="结束日期"
  26. @change="dateSearchChange"
  27. class="search-inner-box">
  28. </el-date-picker>
  29. </div>
  30. </div>
  31. <span>
  32. <myUpload style="float: left;" @uploadBack="uploadBack" :fileInfo="fileInfot"
  33. :fileList="fileInfot.fileList"></myUpload>
  34. <el-button type="primary" @click="mstatuschange" size="medium">{{mstatus?'取消多选':'多选'}}
  35. </el-button>
  36. <el-button type="primary" @click="dialogCli(1)" size="medium" :disabled="!mstatus">导出
  37. </el-button>
  38. <el-button type="danger" @click="dialogCli(2)" size="medium" :disabled="!mstatus">删除</el-button>
  39. </span>
  40. </div>
  41. <div class="img-box">
  42. <div class="boximg">
  43. <div v-for="(item,index) in imgList" :key="item.id" class="img-list">
  44. <div class="img-content">
  45. <img :src="item.fileBase64" alt="" @click="checkimg(item,index)">
  46. <el-checkbox v-if="mstatus" v-model="item.checked" @change="checkAdd(item)"></el-checkbox>
  47. </div>
  48. <input type="text" class="file-name" v-model="item.fileName" :readonly="!item.isRename" @dblclick="renameFile(item)" :style="{'border':!item.isRename ? 'none' : '1px solid #ddd'}" @blur="submitFileName(item)">
  49. </div>
  50. </div>
  51. <el-pagination :page-size="20" class="pageBox" @current-change="currchange" layout="prev, pager, next" background
  52. :total="total">
  53. </el-pagination>
  54. </div>
  55. </div>
  56. <div v-if="bigImgs" class="bigimgcheck">
  57. <i class="el-icon-close close" @click="bigImgs = false"></i>
  58. <img :src="checksrc" alt="">
  59. </div>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import myUpload from "../../../components/upload";
  65. export default {
  66. components: {
  67. myUpload
  68. },
  69. data() {
  70. return {
  71. info: {},
  72. delbox: [],
  73. infotype: "",
  74. typeList: [],
  75. fileInfot: {
  76. type: 'btn',
  77. typename: '新增素材',
  78. btntype: 'success',
  79. limit: 10,
  80. url: '/market/cadvMaterial/upload',
  81. fileList: [],
  82. advType: '',
  83. advTypeName: '',
  84. },
  85. total: 0,
  86. pageSize: 1,
  87. imgList: [],
  88. bigImgs: false,
  89. checksrc: null,
  90. mstatus: false,
  91. checkList: [],
  92. params:{},
  93. fileNameSearch: '',
  94. isRename: true,
  95. //时间排序
  96. sortList:[
  97. {
  98. sortCode: '1',
  99. sortName: '倒序'
  100. },
  101. {
  102. sortCode: '2',
  103. sortName: '正序'
  104. }
  105. ],
  106. timeSort:'倒序',
  107. isDesc: "desc",
  108. dateSearch:[],
  109. createTimeFrom: '',
  110. createTimeTo:''
  111. }
  112. },
  113. methods: {
  114. changeType(v) {
  115. for (let i = 0; i < this.typeList.length; i++) {
  116. if (this.typeList[i].dataCode == v) {
  117. this.fileInfot.advType = v;
  118. this.fileInfot.advTypeName = this.typeList[i].dataName;
  119. // this.infotype = v
  120. this.getlist(this.pageSize);
  121. }
  122. }
  123. },
  124. timeSortChange(v){
  125. if(v==1){
  126. this.isDesc = 'desc'
  127. this.getlist(this.pageSize);
  128. }else if(v==2){
  129. this.isDesc = ''
  130. this.getlist(this.pageSize);
  131. }
  132. },
  133. dateSearchChange(v){
  134. this.createTimeFrom = this.$formatDate(v[0],"YYYY-MM-DD")
  135. this.createTimeTo = this.$formatDate(v[1],"YYYY-MM-DD")
  136. this.getlist(this.pageSize);
  137. },
  138. searchInput(v){
  139. this.fileNameSearch = v
  140. this.getlist(this.pageSize);
  141. },
  142. uploadBack(v) {
  143. this.getlist(this.pageSize);
  144. },
  145. dialogCli(v) {
  146. let params = [];
  147. let paramsf = [];
  148. for (let i = 0; i < this.checkList.length; i++) {
  149. params.push({
  150. id: this.checkList[i].id
  151. })
  152. paramsf.push({
  153. compressFileId: this.checkList[i].compressFileId,
  154. fileName: this.checkList[i].fileName
  155. })
  156. }
  157. let _this = this;
  158. if (v == 2) {
  159. this.$http({
  160. url: "/market/cadvMaterial/delBatchAdvMaterial",
  161. method: "post",
  162. headers: {
  163. "Content-Type": "application/json",
  164. },
  165. data: params,
  166. }).then((res) => {
  167. if (res.data.result === 1) {
  168. _this.$message({
  169. message: res.data.desc,
  170. type: 'error'
  171. });
  172. } else {
  173. _this.$message({
  174. message: '成功',
  175. type: 'success'
  176. });
  177. _this.getlist(_this.pageSize);
  178. }
  179. });
  180. }else if(v == 1){
  181. this.$http({
  182. url: "/market/cadvMaterial/exportAdvMaterialZip",
  183. method: "post",
  184. responseType: 'blob',
  185. headers: {
  186. "Content-Type": "application/json",
  187. },
  188. data: paramsf,
  189. }).then((response) => {
  190. if (window.navigator && window.navigator.msSaveOrOpenBlob) {
  191. let blob = new Blob([response.data], {
  192. type: response.data.type
  193. });
  194. window.navigator.msSaveOrOpenBlob(blob, 'adv.zip');
  195. } else {
  196. /* 火狐谷歌的文件下载方式 */
  197. console.log(response.data.type)
  198. var blob = new Blob([response.data])
  199. var downloadElement = document.createElement('a')
  200. var href = window.URL.createObjectURL(blob);
  201. downloadElement.href = href;
  202. downloadElement.download = 'adv.zip';
  203. document.body.appendChild(downloadElement);
  204. downloadElement.click();
  205. document.body.removeChild(downloadElement);
  206. window.URL.revokeObjectURL(href);
  207. }
  208. });
  209. }
  210. },
  211. renameFile(v){
  212. this.$set(v,'isRename',true)
  213. },
  214. submitFileName(v){
  215. v.isRename = false;
  216. let params = {
  217. id: v.id,
  218. fileName: v.fileName
  219. }
  220. this.$http({
  221. url: "/market/cadvMaterial/updateMkAdvFileName",
  222. method: "post",
  223. headers: {
  224. "Content-Type": "application/json",
  225. },
  226. data: params,
  227. }).then((res) => {
  228. if (res.data.result === 1) {
  229. this.$message({
  230. message: res.data.desc,
  231. type: 'error'
  232. });
  233. } else {
  234. this.$message({
  235. message: '成功',
  236. type: 'success'
  237. });
  238. this.getlist(this.pageSize);
  239. }
  240. });
  241. },
  242. getlist(v) {
  243. let params = {
  244. advType: this.infotype,
  245. fileName: this.fileNameSearch,
  246. isDesc: this.isDesc,
  247. createTimeFrom: this.createTimeFrom,
  248. createTimeTo: this.createTimeTo,
  249. };
  250. if (this.infotype == '08') {
  251. params.advType = ''
  252. }
  253. this.$http({
  254. url: "/market/cadvMaterial/queryPage",
  255. method: "post",
  256. headers: {
  257. "Content-Type": "application/json",
  258. "page": '{"pageNo":"' + v + '","pageSize":"20"}'
  259. },
  260. data: params,
  261. }).then((res) => {
  262. this.total = res.data.totalRecord;
  263. this.imgList = [];
  264. this.imgListold = res.data.data;
  265. res.data.data.forEach(item => {
  266. item.checked = false;
  267. this.imgList.push(item)
  268. })
  269. });
  270. },
  271. // 分页
  272. currchange(v) {
  273. this.pageSize = v;
  274. this.getlist(this.pageSize);
  275. },
  276. gettype() {
  277. this.$http({
  278. url: "/sysmgr/cfgDataDicts/queryMap",
  279. method: "post",
  280. headers: {
  281. "Content-Type": "application/json",
  282. },
  283. data: {
  284. dictCodePks: 'materType'
  285. },
  286. }).then((res) => {
  287. this.typeList = res.data.body.materType;
  288. this.infotype = this.$route.query.type;
  289. this.changeType(this.infotype);
  290. });
  291. },
  292. //切换状态
  293. mstatuschange() {
  294. this.mstatus = !this.mstatus;
  295. this.checkList = [];
  296. this.imgList = [];
  297. for (let i = 0; i < this.imgListold.length; i++) {
  298. let item = this.imgListold[i];
  299. item.checked = false;
  300. this.imgList.push(item)
  301. }
  302. },
  303. //点击图片
  304. checkimg(v, i) {
  305. if (this.mstatus) {
  306. this.imgList[i].checked = !this.imgList[i].checked;
  307. this.checkAdd(v);
  308. return
  309. }
  310. // this.bigImgs = true;
  311. // this.checksrc = v.fileBase64;
  312. this.$http({
  313. url: "/market/cadvMaterial/previewAdvMaterial?compressFileId=" + v.fileId,
  314. method: "post",
  315. responseType: 'blob',
  316. headers: {
  317. "Content-Type": "application/json",
  318. },
  319. data: {},
  320. }).then((res) => {
  321. let _this = this;
  322. if (res && res.data && res.data.size) {
  323. const dataInfo = res.data
  324. let reader = new window.FileReader()
  325. reader.readAsArrayBuffer(dataInfo)
  326. reader.onload = function(e) {
  327. const result = e.target.result
  328. const contentType = dataInfo.type;
  329. const blob = new Blob([result], {
  330. type: contentType
  331. })
  332. const url = window.URL.createObjectURL(blob)
  333. _this.bigImgs = true;
  334. _this.checksrc = url;
  335. }
  336. }
  337. });
  338. },
  339. //选中图片
  340. checkAdd(v) {
  341. let s = true;
  342. for (let i = 0; i < this.checkList.length; i++) {
  343. if (this.checkList[i].id == v.id) {
  344. s = false;
  345. this.checkList.splice(i, 1)
  346. return
  347. }
  348. }
  349. if (s) {
  350. this.checkList.push(v);
  351. }
  352. },
  353. getUser() {
  354. this.userInfo = JSON.parse(window.sessionStorage.userInfo);
  355. },
  356. },
  357. mounted() {
  358. this.gettype();
  359. this.getUser();
  360. // this.getlist(this.pageSize);
  361. },
  362. created() {
  363. },
  364. }
  365. </script>
  366. <style scoped lang="scss">
  367. .container-box {
  368. h2 {
  369. margin-bottom: 20px;
  370. }
  371. .adv-type {
  372. display: flex;
  373. justify-content: space-between;
  374. align-items: center;
  375. .file-name-search{
  376. width: 30%;
  377. }
  378. span {
  379. display: inline-block;
  380. }
  381. }
  382. .img-box {
  383. height: 90%;
  384. .boximg {
  385. height: calc(100% - 190px);
  386. overflow-y: scroll;
  387. display: flex;
  388. flex-wrap: wrap;
  389. // justify-content: space-between;
  390. margin-top: 20px;
  391. .img-list {
  392. display: inline-block;
  393. width: 18%;
  394. margin-right: 2%;
  395. margin-bottom: 20px;
  396. overflow: hidden;
  397. // border: 1px solid #ddd;
  398. border-radius: 3px;
  399. background: #fff;
  400. position: relative;
  401. height: 50%;
  402. .img-content{
  403. border: 1px solid #ddd;
  404. display: flex;
  405. align-items: center;
  406. width: 100%;
  407. height: 80%;
  408. text-align: center;
  409. img {
  410. // width: 100%;
  411. display: block;
  412. max-width: 100%;
  413. max-height: 100%;
  414. // position: absolute;
  415. // top: 0;
  416. // bottom: 0;
  417. margin: auto;
  418. // height: 100%;
  419. }
  420. .el-checkbox {
  421. position: absolute;
  422. top: 0;
  423. right: 0;
  424. display: inline-block;
  425. }
  426. span {}
  427. }
  428. .file-name{
  429. margin-top: 5px;
  430. border: none;
  431. outline: none;
  432. width: 100%;
  433. white-space: nowrap;
  434. text-overflow: ellipsis;
  435. overflow: hidden;
  436. }
  437. }
  438. }
  439. }
  440. .pageBox {
  441. text-align: right;
  442. margin-top: 10px;
  443. }
  444. }
  445. .bigimgcheck {
  446. position: absolute;
  447. top: 0;
  448. left: 0;
  449. width: 100vw;
  450. height: 100vh;
  451. z-index: 10000;
  452. background: rgba(0, 0, 0, .6);
  453. img {
  454. position: absolute;
  455. top: 0;
  456. left: 0;
  457. bottom: 0;
  458. right: 0;
  459. margin: auto;
  460. max-width: 90vw;
  461. }
  462. .close {
  463. position: absolute;
  464. top: 40px;
  465. right: 40px;
  466. font-size: 28px;
  467. color: #fff;
  468. background: rgba(0, 0, 0, .5);
  469. border-radius: 50%;
  470. padding: 5px;
  471. cursor: pointer;
  472. }
  473. }
  474. .search-list-box{
  475. display: flex;
  476. flex-wrap: wrap;
  477. max-width: 50%;
  478. .search-box{
  479. width: 30%;
  480. margin-right: 10px;
  481. margin-bottom: 10px;
  482. .search-inner-box{
  483. width: 100%
  484. }
  485. }
  486. .search-box1{
  487. width: 80%;
  488. }
  489. }
  490. </style>