reportFileTable.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <div class="reportFileTable height_100">
  3. <el-container>
  4. <el-header style="display:flex;justify-content: space-between;">
  5. <div>
  6. <!-- <mySearch :SearchFields="searchFiled" @search="search" :searchValue="searchOption"></mySearch> -->
  7. <el-form :inline="true" class="margin-left_20">
  8. <el-form-item label="名称">
  9. <el-input v-model="searchOption.referencesName" size="small" placeholder="请输入当前名称"></el-input>
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button type="primary" size="small" @click="init">查询</el-button>
  13. </el-form-item>
  14. </el-form>
  15. </div>
  16. <div class="margin-right_10">
  17. <el-button type="primary" size="small" @click="handleAdd()">新增</el-button>
  18. </div>
  19. </el-header>
  20. <el-main class="height_100">
  21. <el-table v-loading="loading" :data="tableData" style="width: 100%;" border
  22. header-row-class-name="custom-table-header" @sort-change="sortChange">
  23. <el-table-column label="#" align="center" width="80px">
  24. <template slot-scope="scope">
  25. <div>
  26. {{ (queryParams.current - 1) * queryParams.size + scope.$index + 1 }}
  27. </div>
  28. </template>
  29. </el-table-column>
  30. <el-table-column v-for="item in columnList" :key="item.value" :prop="item.value"
  31. :render-header="$commonJS.renderHeaderMethods" :label="item.name" :sortable="item.noSort?false:'custom'" align="center">
  32. <template slot-scope="scope">
  33. <div v-if="['name'].includes(item.value)">
  34. <el-tooltip :content="$commonJS.getColumnData(scope.row, item)" placement="top">
  35. <span v-html="$commonJS.getColumnData(scope.row, item)"></span>
  36. </el-tooltip>
  37. </div>
  38. <div v-else v-html="$commonJS.getColumnData(scope.row, item)"></div>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="操作" align="center" width="160">
  42. <template slot-scope="scope">
  43. <el-dropdown split-button type="primary" size="small" @command="handleCommand($event, scope.row)">
  44. <span @click="handleCommand('e', scope.row)">{{scope.row.ifHaveFinalFile !== false?'编辑':'编辑报告内容'}}</span>
  45. <el-dropdown-menu slot="dropdown" class="text-align_center">
  46. <template v-if="scope.row.ifHaveFinalFile !== false">
  47. <el-dropdown-item command="onlineEdit">编辑文档内容</el-dropdown-item>
  48. <el-dropdown-item command="0">下载</el-dropdown-item>
  49. <el-dropdown-item command="1">预览</el-dropdown-item>
  50. </template>
  51. <template v-else>
  52. <el-dropdown-item command="generateReport">生成报告</el-dropdown-item>
  53. </template>
  54. <el-dropdown-item command="2" divided style="color: red;">删除</el-dropdown-item>
  55. </el-dropdown-menu>
  56. </el-dropdown>
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. </el-main>
  61. <el-footer>
  62. <div class="pagination">
  63. <el-pagination :current-page.sync="queryParams.current" :page-size="queryParams.size" :total="total"
  64. @current-change="handleCurrentChange" layout="total, prev, pager, next, jumper" background></el-pagination>
  65. </div>
  66. </el-footer>
  67. </el-container>
  68. <el-dialog :title="title" :visible.sync="dialogVisible" width="500px" append-to-body destroy-on-close
  69. :close-on-click-modal="false" :before-close="handleClose">
  70. <el-form :model="form" :rules="rules" ref="form" label-width="80px" label-position="left">
  71. <el-form-item label="文件名称" prop="referencesName">
  72. <el-input v-model="form.referencesName" placeholder="请输入文件名称"></el-input>
  73. </el-form-item>
  74. <el-form-item label="文件选择" class="margin-bottom_0">
  75. <myUpload :file-list="form.systemFileList" @on-change="onchangeFile" @on-remove="onRemove" :multiple="false" :limit="1"
  76. style="height: 185px;" :autoUpload="true">
  77. </myUpload>
  78. </el-form-item>
  79. <el-form-item label="备注" prop="remark">
  80. <el-input v-model="form.remark" placeholder="请输入备注" type="textarea"></el-input>
  81. </el-form-item>
  82. </el-form>
  83. <div slot="footer" class="dialog-footer">
  84. <el-button @click="handleClose">取 消</el-button>
  85. <el-button type="primary" @click="submit">确 定</el-button>
  86. </div>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script>
  91. import { downLoad2 } from "@/utils"
  92. export default {
  93. props: ['projectId','queryApi','deleteApi'],
  94. data() {
  95. return {
  96. // table数据
  97. tableData: [],
  98. // 分页及总数信息
  99. queryParams: {
  100. current: 1,
  101. size: 10,
  102. },
  103. total: 0,
  104. // 表格字段
  105. columnList: [
  106. {
  107. name: "名称",
  108. type: "String",
  109. value: "referencesName",
  110. },
  111. {
  112. name: "类型",
  113. type: "String",
  114. value: "type",
  115. noSort:true
  116. },
  117. // {
  118. // name: "所属项目",
  119. // type: "String",
  120. // value: "projectName",
  121. // },
  122. {
  123. name: "创建人",
  124. type: "String",
  125. value: "createName",
  126. },
  127. {
  128. name: "创建时间",
  129. type: "String",
  130. value: "createTime",
  131. },
  132. {
  133. name: "备注",
  134. type: "String",
  135. value: "remark",
  136. },
  137. ],
  138. // 检索字段
  139. searchFiled: [
  140. {
  141. label: '名称',
  142. value: 'referencesName',
  143. type: 1,
  144. placeholder: '请输入名称'
  145. },
  146. ],
  147. // 检索字符串
  148. searchOption: {},
  149. //排序字段
  150. sort: [{ "orderBy": "createTime", "orderType": 1 }],
  151. // 表格loading
  152. loading: false,
  153. //
  154. title: '',
  155. // 控制上传弹窗显示
  156. dialogVisible: false,
  157. // 表单数据
  158. form: {
  159. systemFileList: [],
  160. },
  161. // 表单校验
  162. rules: {
  163. referencesName: [{ required: true, message: '请输入文件名称', trigger: 'blur' },],
  164. },
  165. }
  166. },
  167. async mounted() {
  168. // 获取table栏位
  169. // this.columnList = await this.$commonJS.getCustomField('projectTask')
  170. // 获取栏位
  171. // await this.getColumn()
  172. // 获取数据
  173. this.getList()
  174. },
  175. methods: {
  176. init(){
  177. this.queryParams.current = 1
  178. this.getList()
  179. },
  180. // 弹窗确定
  181. submit() {
  182. // 判断文件是否都上传完毕
  183. // this.$commonJS.allUploadFile(this.form)
  184. // this.form.fileGuid=this.form.fileGuids[0]
  185. var guids = this.$commonJS.checkUploadFile(this.form.systemFileList)
  186. if(!guids){
  187. return false
  188. }
  189. if(guids.length>0){
  190. this.form.fileGuid = guids[0]
  191. }else{
  192. this.form.fileGuid = ''
  193. this.$message.warning('文件不能为空')
  194. return false
  195. }
  196. this.$refs.form.validate((valid) => {
  197. if (valid) {
  198. if (!this.form.id) {
  199. this.$api.addReferences(this.form).then(res => {
  200. if (res.code == 200) {
  201. this.$message.success('新增成功')
  202. this.getList()
  203. this.handleClose()
  204. }
  205. }).catch(error => {
  206. })
  207. } else {
  208. this.$api.updateReferences(this.form).then(res => {
  209. if (res.code == 200) {
  210. this.$message.success('编辑成功')
  211. this.getList()
  212. this.handleClose()
  213. }
  214. }).catch(error => {
  215. })
  216. }
  217. }
  218. })
  219. },
  220. // 关闭弹窗
  221. handleClose() {
  222. this.$refs.form.resetFields()
  223. this.form = {
  224. systemFileList: [],
  225. }
  226. this.dialogVisible = false
  227. },
  228. // 上传的文件监听
  229. onchangeFile(file, fileList) {
  230. if (file) {
  231. this.$set(this.form, 'referencesName', file.name)
  232. }
  233. if(!this.form.systemFileList){
  234. this.$set(this.form,'systemFileList',[])
  235. }
  236. if (file.guid) {
  237. let index = this.form.systemFileList.findIndex(item => {
  238. return item.uid == file.uid
  239. })
  240. if (index != -1) {
  241. this.form.systemFileList.splice(index, 1, file)
  242. }
  243. // else {
  244. // this.form.systemFileList.push(file.raw)
  245. // }
  246. } else {
  247. this.form.systemFileList.push(file.raw)
  248. }
  249. },
  250. // 删除上传的文件
  251. onRemove(file, fileList) {
  252. let index = this.form.systemFileList.findIndex(item => {
  253. return item.uid == file.uid
  254. })
  255. if (index != -1) {
  256. this.form.systemFileList.splice(index, 1)
  257. fileList.splice(index, 1)
  258. }
  259. },
  260. // 新增
  261. handleAdd() {
  262. this.title='新增报告文档'
  263. this.form.projectId = this.projectId
  264. this.dialogVisible = true
  265. },
  266. getList() {
  267. let params = {
  268. projectId: this.projectId,//放在外面还是searchQuery里面??
  269. ...this.queryParams,//分页信息
  270. fileName:this.searchOption.referencesName,
  271. // searchQuery: this.$commonJS.objectToString(this.searchOption || {}),//检索条件
  272. orderDTOList: this.sort,//排序信息
  273. }
  274. var api = this.queryApi?this.queryApi : 'getReferences'
  275. this.loading = true
  276. this.$api[api](params).then(res => {
  277. if (res.code == 200) {
  278. this.tableData = res.data.data
  279. this.total = res.data.total
  280. this.loading = false
  281. }
  282. }).catch(error => {
  283. this.tableData = []
  284. this.total = 0
  285. this.loading = false
  286. })
  287. },
  288. // 分页
  289. handleCurrentChange(val) {
  290. this.queryParams.current = val
  291. this.getList()
  292. },
  293. // 排序
  294. sortChange({ column, prop, order }) {
  295. //如需要多个字段排序,则不需要清空
  296. var params = {
  297. sort: this.sort,
  298. column,
  299. prop,
  300. order,
  301. }
  302. this.sort = this.$commonJS.getSortData(params)
  303. this.queryParams.current = 1
  304. this.getList()
  305. },
  306. // 检索
  307. search(val) {
  308. let params = {}
  309. val.forEach(item => {
  310. if (item.type == 3) {
  311. params[item.value] = item.searchValue.map(itemValue => {
  312. return itemValue.value
  313. })
  314. } else {
  315. params[item.value] = item.searchValue.label
  316. }
  317. })
  318. // 返回字符串
  319. this.searchOption = params
  320. // 调用查询接口
  321. this.queryParams.current = 1
  322. this.getList()
  323. },
  324. // 编辑等下拉菜单
  325. handleCommand(ev, row) {
  326. switch (ev) {
  327. case 'e'://编辑
  328. this.handleEdit(row)
  329. break;
  330. case '0'://下载
  331. downLoad2(row.fileGuid)
  332. break;
  333. case '1'://预览
  334. row.fileName = row.referencesName
  335. this.$commonJS.previewFile(row,row.fileGuid,row.type)
  336. break;
  337. case '2'://删除
  338. this.handleDelete(row)
  339. break;
  340. case 'generateReport'://生成报告
  341. this.generateReport(row)
  342. break;
  343. case 'onlineEdit'://在线编辑文档
  344. this.onlineEdit(row)
  345. break;
  346. default:
  347. break;
  348. }
  349. },
  350. //在线编辑文档
  351. onlineEdit(row){
  352. let router = this.$router.resolve({
  353. path: '/onlyOffice',
  354. query: {
  355. projectId:this.projectId,
  356. guid:row.fileGuid,
  357. fileType:row.type,
  358. title:row.referencesName
  359. }
  360. })
  361. window.open(router.href, '_blank')
  362. },
  363. //生成报告
  364. generateReport(row){
  365. var message = this.$message({
  366. message: '报告生成中...',
  367. type: 'warning',
  368. duration:0
  369. });
  370. var params = {
  371. id:row.id
  372. }
  373. this.$api.exportNoveltyReport(params).then(response=>{
  374. if(response.code == 200){
  375. message.close()
  376. this.$message.success('报告生成成功')
  377. this.getList()
  378. }
  379. }).catch(error=>{
  380. message.close()
  381. this.$message.error('报告生成失败')
  382. })
  383. },
  384. // 编辑
  385. handleEdit(data) {
  386. if(data.ifHaveFinalFile === false){
  387. let router = this.$router.resolve({
  388. path: '/exportReport',
  389. query: {
  390. reportTemplateId: data.templateId,
  391. projectId: this.projectId,
  392. reportFileId:data.id,
  393. editModel:true
  394. }
  395. })
  396. window.open(router.href, '_blank')
  397. return
  398. }
  399. var row = JSON.parse(JSON.stringify(data))
  400. row.systemFileList = [{
  401. name: row.referencesName,
  402. guid:row.fileGuid,
  403. }]
  404. this.title='编辑报告文档'
  405. this.form = row
  406. this.dialogVisible = true
  407. },
  408. // 删除
  409. handleDelete(data) {
  410. this.handleDeletes([data.id])
  411. },
  412. handleDeletes(ids) {
  413. this.$confirm('删除后不可恢复', '提示', {
  414. confirmButtonText: '确定',
  415. cancelButtonText: '取消',
  416. type: 'warning'
  417. }).then(() => {
  418. var api = this.deleteApi?this.deleteApi:'deleteReferences'
  419. this.$api[api](ids).then(response => {
  420. if (response.code == 200) {
  421. this.$message.success('删除成功')
  422. this.queryParams.current = 1
  423. this.getList()
  424. }
  425. })
  426. }).catch(() => {
  427. this.$message.info('操作已取消')
  428. });
  429. },
  430. },
  431. }
  432. </script>
  433. <style lang="scss" scoped></style>