index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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.type == 2)">新增</el-button>
  10. <el-button type="warning" @click="remove(tableCheckItems)" :disabled="tableCheckItems.length == 0">删除</el-button>
  11. </div>
  12. <div class="view-dataType-title-search">
  13. <el-input placeholder="请输入架次号" v-model="keyWordData" class="input1">
  14. <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
  15. </el-input>
  16. </div>
  17. </div>
  18. <div class="view-dataType-table">
  19. <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options" :pagination="tableRequset"></LTable>
  20. </div>
  21. <!-- 添加或修改飞参数据信息对话框 -->
  22. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="1000px" :before-close="handleClose">
  23. <el-form ref="form" :inline="true" :rules="rules" :model="form" label-width="80px">
  24. <el-row>
  25. <el-col :span="12">
  26. <el-form-item label="数据源" prop="source">
  27. <el-select v-model="form.source" placeholder="请选择数据源" disabled>
  28. <el-option label="飞参数据" value="1"></el-option>
  29. <el-option label="MDC数据" value="2"></el-option>
  30. </el-select>
  31. </el-form-item>
  32. </el-col>
  33. <el-col :span="12">
  34. <el-form-item label="编目" prop="aircraftId">
  35. <el-select v-model="form.aircraftId" placeholder="请选择编目" disabled>
  36. <el-option v-for="item in aircaftCatalogAll" :key="item.aircaftCatalogId" :label="item.aircaftCatalogCode" :value="item.aircaftCatalogId"> </el-option>
  37. </el-select>
  38. </el-form-item>
  39. </el-col>
  40. </el-row>
  41. <el-row>
  42. <el-col :span="12">
  43. <el-form-item label="飞行时间" prop="flightDate">
  44. <el-date-picker v-model="form.flightDate" type="datetime" placement="bottom-start" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择飞行时间" @change="flightDateChange"></el-date-picker>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="12">
  48. <el-form-item label="架次号" prop="sortieNo">
  49. <el-input disabled v-model="form.sortieNo" placeholder="选择飞行时间自动生成" />
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. <el-row>
  54. <el-col :span="12">
  55. <el-form-item label="上传飞参数据" label-width="110px" prop="ossId">
  56. <FileUpload v-model="form.ossId" :limit="1" :fileSize="500" :fileType="['xls', 'xlsx', 'csv']" />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="12">
  60. <el-form-item label="警告列表导入" label-width="110px">
  61. <el-upload
  62. ref="upload"
  63. :limit="1"
  64. accept=".xlsx, .xls"
  65. :headers="upload.headers"
  66. :action="upload.url + '?updateSupport=' + upload.updateSupport + '&sortieNo=' + form.sortieNo"
  67. :disabled="upload.isUploading"
  68. :on-progress="handleFileUploadProgress"
  69. :on-success="handleFileSuccess"
  70. :auto-upload="false"
  71. :file-list="warnFileList"
  72. >
  73. <el-button size="small" type="primary">点击上传</el-button>
  74. <div class="el-upload__tip text-center" slot="tip">
  75. <div class="el-upload__tip" slot="tip"><el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的数据</div>
  76. <span>仅允许导入xls、xlsx格式文件。</span>
  77. <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
  78. </div>
  79. </el-upload>
  80. </el-form-item>
  81. </el-col>
  82. </el-row>
  83. </el-form>
  84. <span slot="footer" class="dialog-footer">
  85. <el-button @click="handleClose">取 消</el-button>
  86. <el-button type="primary" :loading="submitBtnLoading" @click="submit">确 定</el-button>
  87. </span>
  88. </el-dialog>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import { getDataImport, addDataImport, updateDataImport, removeDataImport, importTemplateApi } from '@/api/als/dataImport'
  94. import { getAircaftCatalogTree } from '@/api/als/sideTree'
  95. import { getAircaftCatalogAll } from '@/api/als/aircraft'
  96. import { deepClone, debounce } from '@/utils/index'
  97. import FileUpload from '@/views/als/components/FileUpload'
  98. import { flattenTree, download } from '../utils/common'
  99. import { getItem } from '@/utils/index'
  100. import { getWarning } from '@/api/als/warning'
  101. export default {
  102. name: 'DataImport',
  103. components: { FileUpload },
  104. data() {
  105. // 这里存放数据
  106. return {
  107. dialogTitle: '新增',
  108. dialogVisible: false,
  109. keyWordData: '',
  110. aircaftModelIdList: [],
  111. submitBtnLoading: false,
  112. currentNodeKey: '',
  113. currentNode: {},
  114. menuTreeData: [],
  115. treeObj: {
  116. title: '所属机种',
  117. activityheight: '275px',
  118. searchIcon: false,
  119. configure: {
  120. children: 'children',
  121. label: 'label'
  122. }
  123. },
  124. rules: {
  125. source: [{ required: true, message: '数据源不能为空', trigger: 'change' }],
  126. aircaftModel: [{ required: true, message: '机型不能为空', trigger: 'change' }],
  127. aircraftId: [{ required: true, message: '编目不能为空', trigger: 'change' }],
  128. flightDate: [{ required: true, message: '飞行时间不能为空', trigger: 'change' }],
  129. sortieNo: [{ required: true, message: '飞架次号不能为空', trigger: 'blur' }],
  130. ossId: [{ required: true, message: '飞参数据不能为空', trigger: 'change' }]
  131. },
  132. typeTree: {
  133. children: 'children',
  134. label: 'label'
  135. },
  136. searchValue: '',
  137. columns: [
  138. {
  139. prop: 'aircraftId',
  140. label: '编目',
  141. render: (h, params) => {
  142. const matchedItem = this.aircaftCatalogAll.find((item) => params.row.aircraftId.trim() === item.aircaftCatalogId.trim())
  143. if (matchedItem) {
  144. return h('span', matchedItem.aircaftCatalogCode)
  145. } else {
  146. return h('span', {}, '')
  147. }
  148. }
  149. },
  150. {
  151. prop: 'sortieNo',
  152. label: '架次号'
  153. },
  154. {
  155. prop: 'source',
  156. label: '数据源',
  157. render: (h, params) => {
  158. if (params.row.source == 1) {
  159. return h('span', { class: 'success-state' }, '飞参数据')
  160. } else {
  161. return h('span', { class: 'success-state' }, 'MDC数据')
  162. }
  163. }
  164. },
  165. {
  166. prop: 'flightDate',
  167. label: '飞行时间'
  168. },
  169. {
  170. prop: 'ossId',
  171. label: '文件编号'
  172. },
  173. {
  174. button: true,
  175. label: '操作',
  176. width: '240px',
  177. group: [
  178. {
  179. name: '编辑',
  180. type: 'text',
  181. round: false,
  182. plain: false,
  183. onClick: (row, index, scope) => {
  184. this.handUpdate(row)
  185. }
  186. },
  187. {
  188. name: '删除',
  189. type: 'text',
  190. round: false,
  191. plain: false,
  192. onClick: (row, index, scope) => {
  193. this.remove([row])
  194. }
  195. }
  196. ]
  197. }
  198. ],
  199. options: {
  200. stripe: true, // 斑马纹
  201. mutiSelect: true, // 多选框
  202. index: false, // 显示序号, 多选则 mutiSelect
  203. loading: false, // 表格动画
  204. initTable: false, // 是否一挂载就加载数据
  205. border: true,
  206. height: 'calc(100vh - 300px)'
  207. },
  208. tableCheckItems: [],
  209. tableData: [],
  210. tableRequset: {
  211. total: 0,
  212. pageIndex: 1,
  213. pageSize: 10,
  214. searchValue: ''
  215. },
  216. form: {
  217. id: '',
  218. ossId: '',
  219. source: '1',
  220. aircraftId: '',
  221. sortieNo: '',
  222. flightDate: '',
  223. status: ''
  224. },
  225. debounceFn: debounce(this.fetch, 500),
  226. aircaftCatalogAll: [],
  227. upload: {
  228. // 是否显示弹出层
  229. open: false,
  230. // 弹出层标题
  231. title: '',
  232. // 是否禁用上传
  233. isUploading: false,
  234. // 是否更新已经存在的用户数据
  235. updateSupport: 0,
  236. // 设置上传的请求头部
  237. headers: { Authorization: getItem('token') },
  238. // 上传的地址
  239. url: '/api/als/warning/importData'
  240. },
  241. warnFileList: [],
  242. uploadFlag: false
  243. }
  244. },
  245. watch: {
  246. keyWord() {
  247. this.tableRequset.pageIndex = 1
  248. this.debounceFn()
  249. }
  250. },
  251. mounted() {
  252. this.getAircaftCatalogTreeAPI()
  253. },
  254. methods: {
  255. async getAircaftCatalogTreeAPI(params) {
  256. try {
  257. const { data } = await getAircaftCatalogTree(params)
  258. this.menuTreeData = data
  259. const getAircaftCatalogAllParams = {
  260. keyWord: '',
  261. aircaftModelIdList: []
  262. }
  263. const { data: data2 } = await getAircaftCatalogAll(getAircaftCatalogAllParams)
  264. this.aircaftCatalogAll = data2
  265. if (data.length) {
  266. this.currentNodeKey = data[0].id
  267. this.currentNode = data[0]
  268. this.aircaftModelIdList = this.getTreeLeafData(data[0]?.children)
  269. .map((e) => e.id)
  270. .toString()
  271. this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
  272. }
  273. } catch (error) {}
  274. },
  275. async removeDataImportAPI(params) {
  276. try {
  277. const { code } = await removeDataImport(params)
  278. if (code === 200) {
  279. this.$message({
  280. type: 'success',
  281. message: '操作成功!'
  282. })
  283. await this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
  284. this.handleClose()
  285. }
  286. } catch (error) {}
  287. },
  288. getTreeLeafData(list) {
  289. const newArr = []
  290. function getLeaf(data, arr) {
  291. data.forEach((e) => {
  292. if (e.type === 2) {
  293. arr.push(e)
  294. }
  295. if (e.children.length) {
  296. getLeaf(e.children, arr)
  297. }
  298. })
  299. }
  300. getLeaf(list, newArr)
  301. return newArr
  302. },
  303. async getDataImportAPI(params) {
  304. if (this.$refs.table) this.$refs.table.clearSelection()
  305. const { keyWord } = this
  306. const { pageSize, pageIndex } = this.tableRequset
  307. const {
  308. data: { list, total }
  309. } = await getDataImport({ pageSize, pageNum: pageIndex, ...params, source: 1 })
  310. this.tableData = list
  311. this.tableRequset.total = total
  312. },
  313. fetch() {
  314. this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
  315. },
  316. async searchClick() {
  317. this.getDataImportAPI({ aircraftId: this.aircaftModelIdList, sortieNo: this.keyWordData })
  318. },
  319. async addDataImportAPI() {
  320. try {
  321. delete this.form.aircaftModelName
  322. const { code } = await addDataImport({ ...this.form })
  323. if (code === 200) {
  324. this.$message({
  325. type: 'success',
  326. message: '操作成功!'
  327. })
  328. this.uploadFlag = true
  329. this.handleClose()
  330. this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
  331. this.submitBtnLoading = false
  332. }
  333. } catch (error) {
  334. this.submitBtnLoading = false
  335. }
  336. },
  337. async updateDataImportAPI() {
  338. try {
  339. const { code } = await updateDataImport({ ...this.form })
  340. if (code === 200) {
  341. this.$message({
  342. type: 'success',
  343. message: '操作成功!'
  344. })
  345. this.handleClose()
  346. this.submitBtnLoading = false
  347. this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
  348. }
  349. } catch (error) {
  350. this.submitBtnLoading = false
  351. }
  352. },
  353. treeNodeClick(data) {
  354. this.$refs.table.clearSelection()
  355. this.currentNodeKey = data.id
  356. this.currentNode = data
  357. this.aircaftModelIdList = this.getTreeLeafData(data.children.length ? data.children : [data])
  358. .map((e) => e.id)
  359. .toString()
  360. if (!this.aircaftModelIdList) {
  361. this.aircaftModelIdList = '#'
  362. }
  363. this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
  364. },
  365. openDialog() {
  366. this.dialogTitle = '新增'
  367. this.dialogVisible = true
  368. this.form.aircraftId = this.currentNodeKey
  369. this.form.aircaftModel = this.currentNode.parentId
  370. },
  371. handleClose() {
  372. this.dialogVisible = false
  373. this.form = {
  374. id: '',
  375. ossId: '',
  376. source: '1',
  377. sortieNo: '',
  378. aircraftId: '',
  379. flightDate: '',
  380. status: ''
  381. }
  382. },
  383. async handUpdate(row) {
  384. this.dialogTitle = '编辑'
  385. this.form = deepClone(row)
  386. // const {
  387. // data: { list, total }
  388. // }=await getWarning({ sortieNo: row.SortieNo })
  389. // if(total!==0){
  390. // }
  391. // console.log('this.form', this.form)
  392. this.dialogVisible = true
  393. },
  394. submit() {
  395. this.$refs['form'].validate((valid) => {
  396. if (valid) {
  397. switch (this.dialogTitle) {
  398. case '编辑':
  399. this.submitBtnLoading = true
  400. this.updateDataImportAPI()
  401. this.submitFileForm()
  402. break
  403. case '新增':
  404. this.submitBtnLoading = true
  405. this.addDataImportAPI()
  406. this.submitFileForm()
  407. break
  408. }
  409. }
  410. })
  411. },
  412. selection(val) {
  413. this.tableCheckItems = val
  414. },
  415. remove(row) {
  416. this.$confirm('是否删除该数据', '提示', {
  417. confirmButtonText: '确定',
  418. cancelButtonText: '取消',
  419. type: 'warning'
  420. })
  421. .then(() => {
  422. this.removeDataImportAPI(row.map((e) => e.id))
  423. })
  424. .catch(() => {})
  425. },
  426. flightDateChange() {
  427. this.form.sortieNo = this.getTime('JC')
  428. // this.form.sortieNo = this.getTime() + '-' + obj?.model
  429. },
  430. getTime(prefix) {
  431. const now = new Date()
  432. const year = now.getFullYear()
  433. const month = ('0' + (now.getMonth() + 1)).slice(-2)
  434. const day = ('0' + now.getDate()).slice(-2)
  435. const hours = ('0' + now.getHours()).slice(-2)
  436. const minutes = ('0' + now.getMinutes()).slice(-2)
  437. const seconds = ('0' + now.getSeconds()).slice(-2)
  438. const dateString = `${year}${month}${day}${hours}${minutes}${seconds}` // 返回格式化的单号
  439. return `${prefix}-${dateString}`
  440. },
  441. /** 导入按钮操作 */
  442. handleImport() {
  443. this.upload.title = '警告列表导入'
  444. this.upload.open = true
  445. },
  446. /** 下载模板操作 */
  447. importTemplate() {
  448. useDownload(importTemplateApi, 'warning_template', {}, '.xlsx')
  449. },
  450. // 文件上传中处理
  451. handleFileUploadProgress(event, file, fileList) {
  452. this.upload.isUploading = true
  453. },
  454. // 文件上传成功处理
  455. handleFileSuccess(response, file, fileList) {
  456. if (this.uploadFlag) {
  457. this.upload.open = false
  458. this.upload.isUploading = false
  459. this.$refs.upload.clearFiles()
  460. this.submitBtnLoading = false
  461. }
  462. // this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', { dangerouslyUseHTMLString: true })
  463. },
  464. // 提交上传文件
  465. submitFileForm() {
  466. this.$refs.upload.submit()
  467. }
  468. }
  469. }
  470. </script>
  471. <style lang="scss" scoped>
  472. @import '../index.scss';
  473. </style>