reportFileTable.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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="getList">查询</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="150">
  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)">编辑</span>
  45. <el-dropdown-menu slot="dropdown" class="text-align_center">
  46. <el-dropdown-item command="0">下载</el-dropdown-item>
  47. <el-dropdown-item command="1">预览</el-dropdown-item>
  48. <el-dropdown-item command="2" divided style="color: red;">删除</el-dropdown-item>
  49. </el-dropdown-menu>
  50. </el-dropdown>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. </el-main>
  55. <el-footer>
  56. <div class="pagination">
  57. <el-pagination :current-page.sync="queryParams.current" :page-size="queryParams.size" :total="total"
  58. @current-change="handleCurrentChange" layout="total, prev, pager, next, jumper" background></el-pagination>
  59. </div>
  60. </el-footer>
  61. </el-container>
  62. <el-dialog :title="title" :visible.sync="dialogVisible" width="500px" append-to-body destroy-on-close
  63. :close-on-click-modal="false" :before-close="handleClose">
  64. <el-form :model="form" :rules="rules" ref="form" label-width="80px" label-position="left">
  65. <el-form-item label="文件名称" prop="referencesName">
  66. <el-input v-model="form.referencesName" placeholder="请输入文件名称"></el-input>
  67. </el-form-item>
  68. <el-form-item label="文件选择" class="margin-bottom_0">
  69. <myUpload :file-list="form.systemFileList" @on-change="onchangeFile" @on-remove="onRemove" :multiple="false"
  70. style="height: 185px;" :autoUpload="true">
  71. </myUpload>
  72. </el-form-item>
  73. <el-form-item label="备注" prop="remark">
  74. <el-input v-model="form.remark" placeholder="请输入备注" type="textarea"></el-input>
  75. </el-form-item>
  76. </el-form>
  77. <div slot="footer" class="dialog-footer">
  78. <el-button @click="handleClose">取 消</el-button>
  79. <el-button type="primary" @click="submit">确 定</el-button>
  80. </div>
  81. </el-dialog>
  82. </div>
  83. </template>
  84. <script>
  85. import { downLoad2 } from "@/utils"
  86. export default {
  87. props: ['projectId'],
  88. data() {
  89. return {
  90. // table数据
  91. tableData: [],
  92. // 分页及总数信息
  93. queryParams: {
  94. current: 1,
  95. size: 10,
  96. },
  97. total: 0,
  98. // 表格字段
  99. columnList: [
  100. {
  101. name: "名称",
  102. type: "String",
  103. value: "referencesName",
  104. },
  105. {
  106. name: "类型",
  107. type: "String",
  108. value: "type",
  109. noSort:true
  110. },
  111. {
  112. name: "所属项目",
  113. type: "String",
  114. value: "projectName",
  115. },
  116. {
  117. name: "创建人",
  118. type: "String",
  119. value: "createName",
  120. },
  121. {
  122. name: "创建时间",
  123. type: "String",
  124. value: "createTime",
  125. },
  126. {
  127. name: "备注",
  128. type: "String",
  129. value: "remark",
  130. },
  131. ],
  132. // 检索字段
  133. searchFiled: [
  134. {
  135. label: '名称',
  136. value: 'referencesName',
  137. type: 1,
  138. placeholder: '请输入名称'
  139. },
  140. ],
  141. // 检索字符串
  142. searchOption: {},
  143. //排序字段
  144. sort: [{ "orderBy": "createTime", "orderType": 1 }],
  145. // 表格loading
  146. loading: false,
  147. //
  148. title: '',
  149. // 控制上传弹窗显示
  150. dialogVisible: false,
  151. // 表单数据
  152. form: {
  153. systemFileList: [],
  154. },
  155. // 表单校验
  156. rules: {
  157. referencesName: [{ required: true, message: '请输入文件名称', trigger: 'blur' },],
  158. },
  159. }
  160. },
  161. async mounted() {
  162. // 获取table栏位
  163. // this.columnList = await this.$commonJS.getCustomField('projectTask')
  164. // 获取栏位
  165. // await this.getColumn()
  166. // 获取数据
  167. this.getList()
  168. },
  169. methods: {
  170. // 弹窗确定
  171. submit() {
  172. // 判断文件是否都上传完毕
  173. this.$commonJS.allUploadFile(this.form)
  174. this.form.fileGuid=this.form.fileGuids[0]
  175. this.$refs.form.validate((valid) => {
  176. if (valid) {
  177. if (!this.form.id) {
  178. this.$api.addReferences(this.form).then(res => {
  179. if (res.code == 200) {
  180. this.$message.success('新增成功')
  181. this.getList()
  182. this.handleClose()
  183. }
  184. }).catch(error => {
  185. })
  186. } else {
  187. this.$api.updateReferences(this.form).then(res => {
  188. if (res.code == 200) {
  189. this.$message.success('编辑成功')
  190. this.getList()
  191. this.handleClose()
  192. }
  193. }).catch(error => {
  194. })
  195. }
  196. }
  197. })
  198. },
  199. // 关闭弹窗
  200. handleClose() {
  201. this.$refs.form.resetFields()
  202. this.form = {
  203. systemFileList: [],
  204. }
  205. this.dialogVisible = false
  206. },
  207. // 上传的文件监听
  208. onchangeFile(file, fileList) {
  209. if (this.form.systemFileList && this.form.systemFileList.length > 0) {
  210. return false
  211. }
  212. if (file) {
  213. this.$set(this.form, 'referencesName', file.name)
  214. }
  215. if (file.guid && this.form.systemFileList && this.form.systemFileList.length > 0) {
  216. let index = this.form.systemFileList.findIndex(item => {
  217. return item.uid == file.uid
  218. })
  219. if (index != -1) {
  220. this.form.systemFileList.splice(index, 1, file)
  221. } else {
  222. this.form.systemFileList.push(file.raw)
  223. }
  224. } else {
  225. this.form.systemFileList.push(file.raw)
  226. }
  227. },
  228. // 删除上传的文件
  229. onRemove(file, fileList) {
  230. let index = this.form.systemFileList.findIndex(item => {
  231. return item.uid == file.uid
  232. })
  233. if (index != -1) {
  234. this.form.systemFileList.splice(index, 1)
  235. }
  236. },
  237. // 新增
  238. handleAdd() {
  239. this.title='新增报告文档'
  240. this.form.projectId = this.projectId
  241. this.dialogVisible = true
  242. },
  243. getList() {
  244. let params = {
  245. projectId: this.projectId,//放在外面还是searchQuery里面??
  246. ...this.queryParams,//分页信息
  247. fileName:this.searchOption.referencesName,
  248. // searchQuery: this.$commonJS.objectToString(this.searchOption || {}),//检索条件
  249. orderDTOList: this.sort,//排序信息
  250. }
  251. this.loading = true
  252. this.$api.getReferences(params).then(res => {
  253. if (res.code == 200) {
  254. this.tableData = res.data.data
  255. this.total = res.data.total
  256. this.loading = false
  257. }
  258. }).catch(error => {
  259. this.tableData = []
  260. this.total = 0
  261. this.loading = false
  262. })
  263. },
  264. // 分页
  265. handleCurrentChange(val) {
  266. this.queryParams.current = val
  267. this.getList()
  268. },
  269. // 排序
  270. sortChange({ column, prop, order }) {
  271. //如需要多个字段排序,则不需要清空
  272. var params = {
  273. sort: this.sort,
  274. column,
  275. prop,
  276. order,
  277. }
  278. this.sort = this.$commonJS.getSortData(params)
  279. this.queryParams.current = 1
  280. this.getList()
  281. },
  282. // 检索
  283. search(val) {
  284. let params = {}
  285. val.forEach(item => {
  286. if (item.type == 3) {
  287. params[item.value] = item.searchValue.map(itemValue => {
  288. return itemValue.value
  289. })
  290. } else {
  291. params[item.value] = item.searchValue.label
  292. }
  293. })
  294. // 返回字符串
  295. this.searchOption = params
  296. // 调用查询接口
  297. this.queryParams.current = 1
  298. this.getList()
  299. },
  300. // 编辑等下拉菜单
  301. handleCommand(ev, row) {
  302. switch (ev) {
  303. case 'e'://编辑
  304. this.handleEdit(row)
  305. break;
  306. case '0'://下载
  307. downLoad2(row.fileGuid)
  308. break;
  309. case '1'://预览
  310. row.fileName = row.referencesName
  311. this.$commonJS.previewFile(row,row.fileGuid,row.type)
  312. break;
  313. case '2'://删除
  314. this.handleDelete(row)
  315. break;
  316. default:
  317. break;
  318. }
  319. },
  320. // 编辑
  321. handleEdit(row) {
  322. row.systemFileList = [{
  323. name: row.referencesName,
  324. guid:row.guid,
  325. }]
  326. this.title='编辑报告文档'
  327. this.form = row
  328. this.dialogVisible = true
  329. },
  330. // 删除
  331. handleDelete(data) {
  332. this.handleDeletes([data.id])
  333. },
  334. handleDeletes(ids) {
  335. this.$confirm('删除后不可恢复', '提示', {
  336. confirmButtonText: '确定',
  337. cancelButtonText: '取消',
  338. type: 'warning'
  339. }).then(() => {
  340. this.$api.deleteReferences(ids).then(response => {
  341. if (response.code == 200) {
  342. this.$message.success('删除成功')
  343. this.queryParams.current = 1
  344. this.getList()
  345. }
  346. })
  347. }).catch(() => {
  348. this.$message.info('操作已取消')
  349. });
  350. },
  351. },
  352. }
  353. </script>
  354. <style lang="scss" scoped></style>