advertmaterial.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <div>
  3. <div class="container">
  4. <div class="container-box">
  5. <h2>素材库</h2>
  6. <div class="adv-type">
  7. <el-select v-model="infotype" @change="changeType">
  8. <el-option v-for="items in typeList" :key="items.dataCode" :label="items.dataName"
  9. :value="items.dataCode">
  10. </el-option>
  11. </el-select>
  12. <span>
  13. <myUpload style="float: left;" @uploadBack="uploadBack" :fileInfo="fileInfot"
  14. :fileList="fileInfot.fileList"></myUpload>
  15. <el-button type="primary" @click="mstatuschange" size="medium">{{mstatus?'取消多选':'多选'}}
  16. </el-button>
  17. <el-button type="primary" @click="dialogCli(1)" size="medium" :disabled="!mstatus">导出
  18. </el-button>
  19. <el-button type="danger" @click="dialogCli(2)" size="medium" :disabled="!mstatus">删除</el-button>
  20. </span>
  21. </div>
  22. <div class="img-box">
  23. <div class="boximg">
  24. <div v-for="(item,index) in imgList" :key="item.id">
  25. <img :src="item.fileBase64" alt="" @click="checkimg(item,index)">
  26. <el-checkbox v-if="mstatus" v-model="item.checked" @change="checkAdd(item)"></el-checkbox>
  27. </div>
  28. </div>
  29. <el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background
  30. :total="total">
  31. </el-pagination>
  32. </div>
  33. </div>
  34. <div v-if="bigImgs" class="bigimgcheck">
  35. <i class="el-icon-close close" @click="bigImgs = false"></i>
  36. <img :src="checksrc" alt="">
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import myUpload from "../../../components/upload";
  43. export default {
  44. components: {
  45. myUpload
  46. },
  47. data() {
  48. return {
  49. info: {},
  50. delbox: [],
  51. infotype: "",
  52. typeList: [],
  53. fileInfot: {
  54. type: 'btn',
  55. typename: '新增素材',
  56. btntype: 'success',
  57. limit: 10,
  58. url: '/market/cadvMaterial/upload',
  59. fileList: [],
  60. advType: '',
  61. advTypeName: '',
  62. },
  63. total: 0,
  64. pageSize: 1,
  65. imgList: [],
  66. bigImgs: false,
  67. checksrc: null,
  68. mstatus: false,
  69. checkList: []
  70. }
  71. },
  72. methods: {
  73. changeType(v) {
  74. for (let i = 0; i < this.typeList.length; i++) {
  75. if (this.typeList[i].dataCode == v) {
  76. this.fileInfot.advType = v;
  77. this.fileInfot.advTypeName = this.typeList[i].dataName;
  78. this.getlist(this.pageSize);
  79. }
  80. }
  81. },
  82. uploadBack(v) {
  83. this.getlist(this.pageSize);
  84. },
  85. dialogCli(v) {
  86. let params = [];
  87. let paramsf = [];
  88. for (let i = 0; i < this.checkList.length; i++) {
  89. params.push({
  90. id: this.checkList[i].id
  91. })
  92. paramsf.push({
  93. compressFileId: this.checkList[i].compressFileId,
  94. fileName: this.checkList[i].fileName
  95. })
  96. }
  97. let _this = this;
  98. if (v == 2) {
  99. this.$http({
  100. url: "/market/cadvMaterial/delBatchAdvMaterial",
  101. method: "post",
  102. headers: {
  103. "Content-Type": "application/json",
  104. },
  105. data: params,
  106. }).then((res) => {
  107. if (res.data.result === 1) {
  108. _this.$message({
  109. message: res.data.desc,
  110. type: 'error'
  111. });
  112. } else {
  113. _this.$message({
  114. message: '成功',
  115. type: 'success'
  116. });
  117. _this.getlist(_this.pageSize);
  118. }
  119. });
  120. }else if(v == 1){
  121. this.$http({
  122. url: "/market/cadvMaterial/exportAdvMaterialZip",
  123. method: "post",
  124. responseType: 'blob',
  125. headers: {
  126. "Content-Type": "application/json",
  127. },
  128. data: paramsf,
  129. }).then((response) => {
  130. if (window.navigator && window.navigator.msSaveOrOpenBlob) {
  131. let blob = new Blob([response.data], {
  132. type: response.data.type
  133. });
  134. window.navigator.msSaveOrOpenBlob(blob, 'adv.zip');
  135. } else {
  136. /* 火狐谷歌的文件下载方式 */
  137. console.log(response.data.type)
  138. var blob = new Blob([response.data])
  139. var downloadElement = document.createElement('a')
  140. var href = window.URL.createObjectURL(blob);
  141. downloadElement.href = href;
  142. downloadElement.download = 'adv.zip';
  143. document.body.appendChild(downloadElement);
  144. downloadElement.click();
  145. document.body.removeChild(downloadElement);
  146. window.URL.revokeObjectURL(href);
  147. }
  148. });
  149. }
  150. },
  151. getlist(v) {
  152. let params = {
  153. advType: this.infotype
  154. };
  155. if (this.infotype == '08') {
  156. params.advType = ''
  157. }
  158. this.$http({
  159. url: "/market/cadvMaterial/queryPage",
  160. method: "post",
  161. headers: {
  162. "Content-Type": "application/json",
  163. "page": '{"pageNo":"' + v + '","pageSize":"20"}'
  164. },
  165. data: params,
  166. }).then((res) => {
  167. this.total = res.data.totalRecord;
  168. this.imgList = [];
  169. this.imgListold = res.data.data;
  170. res.data.data.forEach(item => {
  171. item.checked = false;
  172. this.imgList.push(item)
  173. })
  174. });
  175. },
  176. // 分页
  177. currchange(v) {
  178. this.pageSize = v;
  179. this.getList(this.pageSize);
  180. },
  181. gettype() {
  182. this.$http({
  183. url: "/sysmgr/cfgDataDicts/queryMap",
  184. method: "post",
  185. headers: {
  186. "Content-Type": "application/json",
  187. },
  188. data: {
  189. dictCodePks: 'materType'
  190. },
  191. }).then((res) => {
  192. this.typeList = res.data.body.materType;
  193. this.infotype = this.$route.query.type;
  194. this.changeType(this.infotype);
  195. });
  196. },
  197. //切换状态
  198. mstatuschange() {
  199. this.mstatus = !this.mstatus;
  200. this.checkList = [];
  201. this.imgList = [];
  202. for (let i = 0; i < this.imgListold.length; i++) {
  203. let item = this.imgListold[i];
  204. item.checked = false;
  205. this.imgList.push(item)
  206. }
  207. },
  208. //点击图片
  209. checkimg(v, i) {
  210. if (this.mstatus) {
  211. this.imgList[i].checked = !this.imgList[i].checked;
  212. this.checkAdd(v);
  213. return
  214. }
  215. // this.bigImgs = true;
  216. // this.checksrc = v.fileBase64;
  217. this.$http({
  218. url: "/market/cadvMaterial/previewAdvMaterial?compressFileId=" + v.fileId,
  219. method: "post",
  220. responseType: 'blob',
  221. headers: {
  222. "Content-Type": "application/json",
  223. },
  224. data: {},
  225. }).then((res) => {
  226. let _this = this;
  227. if (res && res.data && res.data.size) {
  228. const dataInfo = res.data
  229. let reader = new window.FileReader()
  230. reader.readAsArrayBuffer(dataInfo)
  231. reader.onload = function(e) {
  232. const result = e.target.result
  233. const contentType = dataInfo.type;
  234. const blob = new Blob([result], {
  235. type: contentType
  236. })
  237. const url = window.URL.createObjectURL(blob)
  238. _this.bigImgs = true;
  239. _this.checksrc = url;
  240. }
  241. }
  242. });
  243. },
  244. //选中图片
  245. checkAdd(v) {
  246. let s = true;
  247. for (let i = 0; i < this.checkList.length; i++) {
  248. if (this.checkList[i].id == v.id) {
  249. s = false;
  250. this.checkList.splice(i, 1)
  251. return
  252. }
  253. }
  254. if (s) {
  255. this.checkList.push(v);
  256. }
  257. },
  258. getUser() {
  259. this.userInfo = JSON.parse(window.sessionStorage.userInfo);
  260. },
  261. },
  262. mounted() {
  263. this.gettype();
  264. this.getUser();
  265. // this.getlist(this.pageSize);
  266. },
  267. created() {
  268. },
  269. }
  270. </script>
  271. <style scoped lang="scss">
  272. .container-box {
  273. h2 {
  274. margin-bottom: 20px;
  275. }
  276. .adv-type {
  277. display: flex;
  278. justify-content: space-between;
  279. span {
  280. display: inline-block;
  281. }
  282. }
  283. .img-box {
  284. height: 100%;
  285. .boximg {
  286. height: calc(100% - 190px);
  287. overflow-y: scroll;
  288. display: flex;
  289. flex-wrap: wrap;
  290. // justify-content: space-between;
  291. margin-top: 20px;
  292. div {
  293. display: inline-block;
  294. width: 18%;
  295. margin-right: 2%;
  296. margin-bottom: 20px;
  297. overflow: hidden;
  298. border: 1px solid #ddd;
  299. border-radius: 3px;
  300. background: #fff;
  301. position: relative;
  302. height: 45%;
  303. img {
  304. width: 100%;
  305. position: absolute;
  306. top: 0;
  307. bottom: 0;
  308. margin: auto;
  309. // height: 100%;
  310. }
  311. .el-checkbox {
  312. position: absolute;
  313. top: 0;
  314. right: 0;
  315. display: inline-block;
  316. }
  317. span {}
  318. }
  319. }
  320. }
  321. .pageBox {
  322. text-align: right;
  323. margin-top: 10px;
  324. }
  325. }
  326. .bigimgcheck {
  327. position: absolute;
  328. top: 0;
  329. left: 0;
  330. width: 100vw;
  331. height: 100vh;
  332. z-index: 10000;
  333. background: rgba(0, 0, 0, .6);
  334. img {
  335. position: absolute;
  336. top: 0;
  337. left: 0;
  338. bottom: 0;
  339. right: 0;
  340. margin: auto;
  341. max-width: 90vw;
  342. }
  343. .close {
  344. position: absolute;
  345. top: 40px;
  346. right: 40px;
  347. font-size: 28px;
  348. color: #fff;
  349. background: rgba(0, 0, 0, .5);
  350. border-radius: 50%;
  351. padding: 5px;
  352. cursor: pointer;
  353. }
  354. }
  355. </style>