filescenter.vue 14 KB

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