filescenter.vue 16 KB

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