index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="view-table-content">
  3. <div class="view-dataSpecies-left">
  4. <MenuTree :currentNodeKey="currentNodeKey" nodeKey="id" :treedata="menuTreeData" @TreeNodeclick="treeNodeClick" v-bind="treeObj"> </MenuTree>
  5. </div>
  6. <div class="view-dataSpecies-right">
  7. <div class="view-dataType-title">
  8. <div class="view-dataType-title-btn">
  9. <el-button type="success" @click="openDialog()" :disabled="currentNode && currentNode.type == 0">新增</el-button>
  10. <el-button type="warning" @click="remove(tableCheckItems)" :disabled="tableCheckItems.length == 0">删除</el-button>
  11. <el-button type="primary">导入模板</el-button>
  12. <el-button type="primary">导出模板</el-button>
  13. </div>
  14. <div class="view-dataType-title-search">
  15. <el-input placeholder="请输入关键字" v-model="keyWord" class="input1">
  16. <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
  17. </el-input>
  18. </div>
  19. </div>
  20. <div class="view-dataType-table">
  21. <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options" :pagination="tableRequset"></LTable>
  22. </div>
  23. <!-- 添加或修改技术资料对话框 -->
  24. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
  25. <el-form ref="form" :model="form" label-width="80px">
  26. <el-form-item label="名称" prop="name">
  27. <el-input v-model="form.name" placeholder="请输入名称" />
  28. </el-form-item>
  29. <el-form-item label="作者" prop="author">
  30. <el-input v-model="form.author" placeholder="请输入作者" />
  31. </el-form-item>
  32. <el-form-item label="出版时间" prop="publicationDate">
  33. <el-date-picker clearable v-model="form.publicationDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择出版时间"> </el-date-picker>
  34. </el-form-item>
  35. <el-form-item label="文件Id" prop="ossId">
  36. <el-input v-model="form.ossId" placeholder="请输入文件Id" />
  37. </el-form-item>
  38. </el-form>
  39. <span slot="footer" class="dialog-footer">
  40. <el-button @click="handleClose">取 消</el-button>
  41. <el-button type="primary" @click="submit">确 定</el-button>
  42. </span>
  43. </el-dialog>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import { getTechnicalDoc, getAircaftTypeAndModelTree, addTechnicalDoc, updateTechnicalDoc, removeTechnicalDoc } from '@/api/als/technicalDoc'
  49. import { deepClone, debounce } from '@/utils/index'
  50. export default {
  51. name: 'TechnicalDoc',
  52. components: {},
  53. data() {
  54. // 这里存放数据
  55. return {
  56. dialogTitle: '新增',
  57. dialogVisible: false,
  58. keyWord: '',
  59. aircaftModelIdList: [],
  60. currentNodeKey: null,
  61. currentNode: null,
  62. menuTreeData: [],
  63. treeObj: {
  64. title: '所属机种',
  65. activityheight: '275px',
  66. searchIcon: false,
  67. configure: {
  68. children: 'children',
  69. label: 'label'
  70. }
  71. },
  72. typeTree: {
  73. children: 'children',
  74. label: 'label'
  75. },
  76. searchValue: '',
  77. columns: [
  78. { prop: 'id', label: '编号' },
  79. {
  80. prop: 'name',
  81. label: '名称'
  82. },
  83. {
  84. prop: 'author',
  85. label: '作者'
  86. },
  87. {
  88. prop: 'publicationDate',
  89. label: '出版时间'
  90. },
  91. {
  92. prop: 'type',
  93. label: '资料类型'
  94. },
  95. {
  96. prop: 'ossId',
  97. label: '文件Id'
  98. },
  99. {
  100. button: true,
  101. label: '操作',
  102. width: '240px',
  103. group: [
  104. {
  105. name: '编辑',
  106. type: 'text',
  107. round: false,
  108. plain: false,
  109. onClick: (row, index, scope) => {
  110. _this.handUpdate(row)
  111. }
  112. },
  113. {
  114. name: '删除',
  115. type: 'text',
  116. round: false,
  117. plain: false,
  118. onClick: (row, index, scope) => {
  119. _this.remove([row])
  120. }
  121. }
  122. ]
  123. }
  124. ],
  125. options: {
  126. stripe: true, // 斑马纹
  127. mutiSelect: true, // 多选框
  128. index: false, // 显示序号, 多选则 mutiSelect
  129. loading: false, // 表格动画
  130. initTable: false, // 是否一挂载就加载数据
  131. border: true,
  132. height: 'calc(100vh - 300px)'
  133. },
  134. tableCheckItems: [],
  135. tableData: [],
  136. tableRequset: {
  137. total: 0,
  138. pageIndex: 1,
  139. pageSize: 20,
  140. searchValue: ''
  141. },
  142. form: {
  143. id: '',
  144. name: '',
  145. author: '',
  146. publicationDate: '',
  147. type: '',
  148. ossId: '',
  149. tenantId: '',
  150. version: '',
  151. delFlag: '',
  152. createBy: '',
  153. createTime: '',
  154. updateBy: '',
  155. updateTime: ''
  156. },
  157. debounceFn: debounce(this.fetch, 500)
  158. }
  159. },
  160. watch: {
  161. keyWord() {
  162. this.tableRequset.pageIndex = 1
  163. this.debounceFn()
  164. }
  165. },
  166. mounted() {
  167. this.getAircaftTypeAndModelTreeAPI()
  168. },
  169. methods: {
  170. async getAircaftTypeAndModelTreeAPI(params) {
  171. const { data } = await getAircaftTypeAndModelTree(params)
  172. this.menuTreeData = data
  173. if (data.length) {
  174. this.currentNodeKey = data[0].value
  175. this.currentNode = data[0]
  176. this.aircaftModelIdList = this.getTreeLeafData(data[0]?.children).map((e) => e.id)
  177. this.getTechnicalDocAPI({ aircaftModelIdList: this.aircaftModelIdList })
  178. }
  179. },
  180. async removeTechnicalDocAPI(params) {
  181. try {
  182. const { success } = await removeTechnicalDoc(params)
  183. if (success) {
  184. this.$message({
  185. type: 'success',
  186. message: '操作成功!'
  187. })
  188. await this.getTechnicalDocAPI({ aircaftModelIdList: this.aircaftModelIdList })
  189. this.handleClose()
  190. }
  191. } catch (error) {}
  192. },
  193. getTreeLeafData(list) {
  194. const newArr = []
  195. function getLeaf(data, arr) {
  196. data.forEach((e) => {
  197. if (e.type === 1) {
  198. arr.push(e)
  199. }
  200. if (e.children.length) {
  201. getLeaf(e.children, arr)
  202. }
  203. })
  204. }
  205. getLeaf(list, newArr)
  206. return newArr
  207. },
  208. async getTechnicalDocAPI(params) {
  209. if (this.$refs.table) this.$refs.table.clearSelection()
  210. const { keyWord } = this
  211. const { pageSize, pageIndex } = this.tableRequset
  212. const {
  213. data: { list, total }
  214. } = await getTechnicalDoc({ pageSize, pageIndex, keyWord, ...params })
  215. this.tableData = list
  216. this.tableRequset.total = total
  217. },
  218. fetch() {
  219. this.getTechnicalDocAPI({ aircaftModelIdList: this.aircaftModelIdList })
  220. },
  221. searchClick() {
  222. this.getTechnicalDocAPI({ aircaftModelIdList: this.aircaftModelIdList })
  223. },
  224. async addTechnicalDocAPI() {
  225. try {
  226. delete this.form.aircaftModelName
  227. const { success } = await addTechnicalDoc({ ...this.form })
  228. if (success) {
  229. this.$message({
  230. type: 'success',
  231. message: '操作成功!'
  232. })
  233. this.getTechnicalDocAPI({ aircaftModelIdList: this.aircaftModelIdList })
  234. }
  235. } catch (error) {}
  236. },
  237. async updateTechnicalDocAPI() {
  238. try {
  239. const { success } = await updateTechnicalDoc({ ...this.form })
  240. if (success) {
  241. this.$message({
  242. type: 'success',
  243. message: '操作成功!'
  244. })
  245. this.getTechnicalDocAPI({ aircaftModelIdList: this.aircaftModelIdList })
  246. }
  247. } catch (error) {}
  248. },
  249. treeNodeClick(data) {
  250. this.$refs.table.clearSelection()
  251. this.currentNodeKey = data.id
  252. this.currentNode = data
  253. this.aircaftModelIdList = this.getTreeLeafData(data.children.length ? data.children : [data]).map((e) => e.id)
  254. this.getTechnicalDocAPI({ aircaftModelIdList: this.aircaftModelIdList })
  255. },
  256. openDialog() {
  257. this.dialogTitle = '新增'
  258. this.dialogVisible = true
  259. this.form.aircaftModelName = this.currentNode.label
  260. this.form.aircaftModelId = this.currentNode.id
  261. },
  262. handleClose() {
  263. this.dialogVisible = false
  264. this.form = {
  265. id: '',
  266. name: '',
  267. author: '',
  268. publicationDate: '',
  269. type: '',
  270. ossId: '',
  271. tenantId: '',
  272. version: '',
  273. delFlag: '',
  274. createBy: '',
  275. createTime: '',
  276. updateBy: '',
  277. updateTime: ''
  278. }
  279. },
  280. handUpdate(row) {
  281. this.dialogTitle = '编辑'
  282. this.form = deepClone(row)
  283. this.dialogVisible = true
  284. },
  285. submit() {
  286. switch (this.dialogTitle) {
  287. case '编辑':
  288. this.updateTechnicalDocAPI()
  289. this.handleClose()
  290. break
  291. case '新增':
  292. this.addTechnicalDocAPI()
  293. this.handleClose()
  294. break
  295. }
  296. },
  297. selection(val) {
  298. this.tableCheckItems = val
  299. },
  300. remove(row) {
  301. this.$confirm('是否删除该机种', '提示', {
  302. confirmButtonText: '确定',
  303. cancelButtonText: '取消',
  304. type: 'warning'
  305. })
  306. .then(() => {
  307. this.removeTechnicalDocAPI(row.map((e) => e.id))
  308. })
  309. .catch(() => {})
  310. }
  311. }
  312. }
  313. </script>
  314. <style lang="scss" scoped>
  315. @import '../index.scss';
  316. </style>