filescenter.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option" :table-loading="loading" :data="assemblyForm.filesList" :page.sync="page"
  4. :permission="permissionList" :before-open="beforeOpen" id="out-table" :header-cell-class-name="headerClassName"
  5. v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave" @row-del="rowDel"
  6. @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
  7. @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
  8. <template slot="menuLeft">
  9. <el-button type="primary" size="small" icon="el-icon-plus" plain
  10. :disabled="!assemblyForm.id || detailData.seeDisabled || disabled" @click="addBtnfun">新 增
  11. </el-button>
  12. <el-button type="danger" size="small" icon="el-icon-delete" plain :disabled="detailData.seeDisabled || disabled"
  13. @click="handleDelete">删 除
  14. </el-button>
  15. </template>
  16. <template slot="menu" slot-scope="{ row, index }">
  17. <el-button size="small" v-if="row.isImage==0" icon="el-icon-view" type="text" @click="rowDownload(row, index)">下 载
  18. </el-button>
  19. <el-button size="small" v-if="row.isImage==1" icon="el-icon-view" type="text" @click="rowPreview(row, index)">预 览
  20. </el-button>
  21. <el-button v-if="row.edit" size="small" icon="el-icon-edit" type="text"
  22. :disabled="detailData.seeDisabled || disabled" @click="rowCell(row, index)">保 存
  23. </el-button>
  24. <el-button v-else size="small" icon="el-icon-edit" type="text" :disabled="detailData.seeDisabled || disabled"
  25. @click="rowEdit(row, index)">修 改
  26. </el-button>
  27. <!-- <el-button size="small" icon="el-icon-delete" type="text" :disabled="detailData.seeDisabled || disabled"
  28. @click="rowDel(row, index)">删 除
  29. </el-button> -->
  30. </template>
  31. <template slot-scope="scope" slot="serialNo">
  32. <el-input v-if="scope.row.edit" type="age" style="width: 100%;" v-model="scope.row.serialNo" size="small"
  33. autocomplete="off" :disabled="detailData.seeDisabled || disabled" clearable placeholder="请输入自定义序号"></el-input>
  34. <span v-else>{{ scope.row.serialNo }}</span>
  35. </template>
  36. <template slot="url" slot-scope="scope">
  37. <el-input v-if="scope.row.edit" v-model="scope.row.url" style="width: 80%;" size="small">
  38. </el-input>
  39. <el-button style="width: 20%" size="small" v-if="scope.row.edit" @click="uploadFiles(scope.row, scope.index)">
  40. 附件
  41. </el-button>
  42. <span v-else style="color: #1e9fff;" @click="rowDownload(scope.row, scope.index)">
  43. {{ scope.row.url }}
  44. </span>
  45. </template>
  46. <template slot-scope="scope" slot="isImage">
  47. <el-select v-if="scope.row.edit" v-model="scope.row.isImage" size="small" placeholder="请选择">
  48. <el-option v-for="item in isImageData" :key="item.value" :label="item.label" :value="item.value">
  49. </el-option>
  50. </el-select>
  51. <span v-else>{{ scope.row.isImage ? '是' : '否' }}</span>
  52. </template>
  53. <template slot-scope="scope" slot="remarks">
  54. <el-input v-if="scope.row.edit" v-model="scope.row.remarks" size="small">
  55. </el-input>
  56. <span v-else>{{ scope.row.remarks }}</span>
  57. </template>
  58. </avue-crud>
  59. <el-dialog title="上传附件" append-to-body :visible.sync="excelBox" width="555px" v-dialog-drag placeholder="请输入">
  60. <avue-form :option="excelOption" v-model="excelForm" table-loading="excelLoading" :upload-before="uploadBefore"
  61. :upload-after="uploadAfter">
  62. </avue-form>
  63. </el-dialog>
  64. <!--附近弹窗-->
  65. <el-dialog width="80%" title="附件" :visible.sync="urlVisible" :close-on-click-modal="false" append-to-body>
  66. <div style="width: 50%;height: 50%;margin: 0 auto">
  67. <img :src="imgUrl" alt="" style="width: 100%;height: 100%;" />
  68. </div>
  69. </el-dialog>
  70. </basic-container>
  71. </template>
  72. <script>
  73. import { filescenterList, filescenterDetail, filescenterSubmit, filescenterRemove } from "@/api/iosBasicData/filescenter";
  74. import { mapGetters } from "vuex";
  75. import { requiredMessage } from "@/util/messageReminder";
  76. import website from "@/config/website";
  77. import { getToken } from "@/util/auth";
  78. export default {
  79. props: {
  80. detailData: {
  81. type: Boolean
  82. },
  83. assemblyForm: {
  84. type: Object
  85. },
  86. disabled: {
  87. type: Boolean,
  88. default: false,
  89. },
  90. },
  91. data() {
  92. return {
  93. // 上传附件弹窗
  94. excelBox: false,
  95. selectIndex: null,
  96. excelForm: {},
  97. excelOption: {
  98. submitBtn: false,
  99. emptyBtn: false,
  100. column: [
  101. {
  102. label: "附件上传",
  103. prop: "excelFile",
  104. type: "upload",
  105. drag: true,
  106. dataType: "string",
  107. loadText: "模板上传中,请稍等",
  108. span: 24,
  109. propsHttp: {
  110. res: "data",
  111. url: "link"
  112. },
  113. action: "/api/blade-resource/oss/endpoint/put-file"
  114. }
  115. ]
  116. },
  117. // 是否图片
  118. isImageData: [{
  119. label: '否',
  120. value: 0
  121. }, {
  122. label: '是',
  123. value: 1
  124. }],
  125. urlVisible: false, // 附件的上传
  126. imgUrl: '', // 弹窗展示的图片地址
  127. form: {},
  128. query: {},
  129. loading: false,
  130. page: {
  131. pageSize: 10,
  132. currentPage: 1,
  133. total: 0
  134. },
  135. selectionList: [],
  136. option: {
  137. height: 'auto',
  138. calcHeight: 30,
  139. tip: false,
  140. searchShow: true,
  141. searchMenuSpan: 6,
  142. border: true,
  143. index: true,
  144. viewBtn: true,
  145. selection: true,
  146. dialogClickModal: false,
  147. cellBtn: true, // 行编辑
  148. column: [
  149. // {
  150. // label: "业务类型",
  151. // prop: "businessType",
  152. // cell: true,
  153. // },
  154. // {
  155. // label: "主表 Id",
  156. // prop: "pid",
  157. // rules: [{
  158. // required: true,
  159. // message: "请输入主表 Id",
  160. // trigger: "blur"
  161. // }]
  162. // },
  163. // {
  164. // label: "明细 Id",
  165. // prop: "itemId",
  166. // rules: [{
  167. // required: true,
  168. // message: "请输入明细 Id",
  169. // trigger: "blur"
  170. // }]
  171. // },
  172. {
  173. label: "自定义序号",
  174. prop: "serialNo",
  175. width: "100"
  176. },
  177. // {
  178. // label: "业务编号",
  179. // prop: "billNo",
  180. // },
  181. // {
  182. // label: "MB/L NO",
  183. // prop: "mblno",
  184. // },
  185. // {
  186. // label: "HB/L NO",
  187. // prop: "hblno",
  188. // },
  189. {
  190. label: "文件名",
  191. prop: "fileName",
  192. width: "120",
  193. },
  194. {
  195. label: "文件扩展名",
  196. prop: "fileExt",
  197. width: "120",
  198. },
  199. {
  200. label: "文件地址",
  201. prop: "url",
  202. width: "500"
  203. },
  204. {
  205. label: "是否图片",
  206. prop: "isImage",
  207. },
  208. {
  209. label: "文件接收日期",
  210. prop: "receivedData",
  211. width: "160",
  212. },
  213. // {
  214. // label: "排序",
  215. // prop: "sort",
  216. // },
  217. {
  218. label: "备注",
  219. prop: "remarks",
  220. },
  221. ]
  222. },
  223. data: []
  224. };
  225. },
  226. computed: {
  227. ...mapGetters(["permission"]),
  228. permissionList() {
  229. return {
  230. addBtn: this.vaildData(this.permission.filescenter_add, false),
  231. viewBtn: this.vaildData(this.permission.filescenter_view, false),
  232. delBtn: this.vaildData(this.permission.filescenter_delete, false),
  233. editBtn: this.vaildData(this.permission.filescenter_edit, false)
  234. };
  235. },
  236. ids() {
  237. let ids = [];
  238. this.selectionList.forEach(ele => {
  239. ids.push(ele.id);
  240. });
  241. return ids.join(",");
  242. }
  243. },
  244. methods: {
  245. // 新增
  246. addBtnfun() {
  247. this.assemblyForm.filesList.push({
  248. pid:this.assemblyForm.id,
  249. edit: true
  250. })
  251. // this.$refs.crud.rowAdd()
  252. },
  253. // 点击附件按钮
  254. uploadFiles(row, index) {
  255. this.selectIndex = index
  256. this.excelBox = true
  257. },
  258. uploadBefore(file, done, loading) {
  259. done();
  260. loading = true;
  261. },
  262. uploadAfter(res, done, loading, column) {
  263. this.excelBox = false;
  264. this.$message.success("上传成功!");
  265. this.$set(this.assemblyForm.filesList[this.selectIndex], 'url', res.link)
  266. this.$set(this.assemblyForm.filesList[this.selectIndex], 'fileName', res.originalName)
  267. this.$set(this.assemblyForm.filesList[this.selectIndex], 'fileExt', res.originalName)
  268. this.$set(this.assemblyForm.filesList[this.selectIndex], 'serialNo',this.selectIndex+1)
  269. this.$set(this.assemblyForm.filesList[this.selectIndex], 'isImage',0)
  270. loading = false;
  271. done();
  272. },
  273. // 下载
  274. rowDownload(row) {
  275. console.log(row, 340)
  276. // window.open(row.url)
  277. window.open(`${row.url}?${this.website.tokenHeader}=${getToken()}`);
  278. // this.$axios.get(row.url,{
  279. // responseType:'blob',
  280. // }).then((response)=>{
  281. // console.log(response,346)
  282. // const blob = new Blob([response.data],{type:'application/;charset=utf-8'})
  283. // const a = document.createElement("a");
  284. // a.href = URL.createObjectURL(blob)
  285. // a.download = 'fileName123132123'
  286. // document.body.appendChild(a)
  287. // a.click()
  288. // document.body.removeChild(a)
  289. // })
  290. },
  291. // 预览
  292. rowPreview(row, index) {
  293. this.imgUrl = row.url
  294. this.urlVisible = true
  295. },
  296. // 编辑
  297. rowEdit(row, index) {
  298. this.$set(row, 'edit', true)
  299. },
  300. // 保存
  301. rowCell(row, index) {
  302. // 需要加判断是否必填的数据
  303. const messageData = [
  304. {
  305. name: '自定义序号',
  306. value: 'serialNo',
  307. },
  308. {
  309. name: '文件地址',
  310. value: 'url',
  311. },
  312. ]
  313. // 保存
  314. if (!requiredMessage(row, messageData)) {
  315. return
  316. }
  317. if (!row.isImage && row.isImage != 0) {
  318. this.$message({
  319. message: '请选择是否是图片',
  320. type: 'warning'
  321. });
  322. return;
  323. }
  324. row.sort = index
  325. row.businessType = 'SE'
  326. row.pid = this.assemblyForm.id
  327. row.hblno = this.assemblyForm.hblno
  328. row.mblno = this.assemblyForm.mblno
  329. row.serialNo = row.serialNo
  330. // 保存接口
  331. this.filescenterSubmitfun(row)
  332. },
  333. // 保存接口
  334. filescenterSubmitfun(row) {
  335. console.log(row, 337)
  336. filescenterSubmit(row).then(res => {
  337. this.$message({
  338. type: "success",
  339. message: "操作成功!"
  340. });
  341. // 编辑
  342. this.$set(row, 'edit', !row.edit)
  343. this.$emit('billsDetailfun')
  344. })
  345. },
  346. rowSave(row, done, loading) {
  347. filescenterSubmit(row).then(() => {
  348. this.onLoad(this.page);
  349. this.$message({
  350. type: "success",
  351. message: "操作成功!"
  352. });
  353. done();
  354. }, error => {
  355. loading();
  356. window.console.log(error);
  357. });
  358. },
  359. rowUpdate(row, index, done, loading) {
  360. filescenterSubmit(row).then(() => {
  361. this.onLoad(this.page);
  362. this.$message({
  363. type: "success",
  364. message: "操作成功!"
  365. });
  366. done();
  367. }, error => {
  368. loading();
  369. console.log(error);
  370. });
  371. },
  372. rowDel(row,index) {
  373. this.$confirm("确定将选择数据删除?", {
  374. confirmButtonText: "确定",
  375. cancelButtonText: "取消",
  376. type: "warning"
  377. })
  378. .then(() => {
  379. if (row.id) {
  380. this.assemblyForm.filesList.splice(index, 1)
  381. return filescenterRemove(row.id);
  382. } else {
  383. this.assemblyForm.filesList.splice(index, 1)
  384. }
  385. })
  386. .then(() => {
  387. this.onLoad(this.page);
  388. this.$message({
  389. type: "success",
  390. message: "操作成功!"
  391. });
  392. });
  393. },
  394. handleDelete() {
  395. if (this.selectionList.length === 0) {
  396. this.$message.warning("请选择至少一条数据");
  397. return;
  398. }
  399. // this.$confirm("确定将选择数据删除?", {
  400. // confirmButtonText: "确定",
  401. // cancelButtonText: "取消",
  402. // type: "warning"
  403. // })
  404. // .then(() => {
  405. // return filescenterRemove(this.ids);
  406. // })
  407. // .then(() => {
  408. // this.onLoad(this.page);
  409. // this.$message({
  410. // type: "success",
  411. // message: "操作成功!"
  412. // });
  413. // this.$refs.crud.toggleSelection();
  414. // });
  415. this.$confirm("确定将选择数据删除?", {
  416. confirmButtonText: "确定",
  417. cancelButtonText: "取消",
  418. type: "warning"
  419. }).then(() => {
  420. let multiList = []
  421. let arr = []
  422. multiList = this.selectionList
  423. arr = this.assemblyForm.filesList
  424. // 获取有id 的数据
  425. const itemsWithId = multiList.filter(item =>item.id!=null);
  426. let arrIds = itemsWithId.map(item => item.id) // 获取id 数据
  427. // 把选中的删除掉
  428. multiList.forEach((item) => {
  429. for (let index in arr) {
  430. if (JSON.stringify(item) == JSON.stringify(arr[index])) {
  431. arr.splice(Number(index), 1)
  432. }
  433. }
  434. })
  435. if (itemsWithId.length != 0) {
  436. filescenterRemove(arrIds.join(',')).then(res => {
  437. this.$message.success("删除成功");
  438. })
  439. }
  440. })
  441. },
  442. beforeOpen(done, type) {
  443. if (["edit", "view"].includes(type)) {
  444. filescenterDetail(this.form.id).then(res => {
  445. this.form = res.data.data;
  446. });
  447. }
  448. done();
  449. },
  450. searchReset() {
  451. this.query = {};
  452. this.onLoad(this.page);
  453. },
  454. searchChange(params, done) {
  455. this.query = params;
  456. this.page.currentPage = 1;
  457. this.onLoad(this.page, params);
  458. done();
  459. },
  460. selectionChange(list) {
  461. this.selectionList = list;
  462. },
  463. selectionClear() {
  464. this.selectionList = [];
  465. this.$refs.crud.toggleSelection();
  466. },
  467. currentChange(currentPage) {
  468. this.page.currentPage = currentPage;
  469. },
  470. sizeChange(pageSize) {
  471. this.page.pageSize = pageSize;
  472. },
  473. refreshChange() {
  474. this.onLoad(this.page, this.query);
  475. },
  476. getData(form) {
  477. this.assemblyForm = form
  478. this.onLoad(this.page, form);
  479. },
  480. onLoad(page, params = {}) {
  481. if (this.assemblyForm.id) {
  482. this.loading = true;
  483. filescenterList(page.currentPage, page.pageSize, Object.assign({ pid: this.assemblyForm.id }, this.query)).then(res => {
  484. const data = res.data.data;
  485. this.page.total = data.total;
  486. this.data = data.records;
  487. this.loading = false;
  488. this.selectionClear();
  489. });
  490. }
  491. },
  492. // 更改表格颜色
  493. headerClassName(tab) {
  494. //颜色间隔
  495. let back = ""
  496. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  497. if (tab.columnIndex % 2 === 0) {
  498. back = "back-one"
  499. } else if (tab.columnIndex % 2 === 1) {
  500. back = "back-two"
  501. }
  502. }
  503. return back;
  504. },
  505. }
  506. };
  507. </script>
  508. <style scoped>
  509. ::v-deep#out-table .back-one {
  510. background: #ecf5ff !important;
  511. text-align: center;
  512. padding: 4px 0;
  513. }
  514. ::v-deep#out-table .back-two {
  515. background: #ecf5ff !important;
  516. text-align: center;
  517. padding: 4px 0;
  518. }
  519. </style>