123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- <template>
- <div class="view-table-content">
- <div class="view-dataSpecies-left">
- <MenuTree :currentNodeKey="currentNodeKey" nodeKey="id" :treedata="menuTreeData" @TreeNodeclick="treeNodeClick" v-bind="treeObj"> </MenuTree>
- </div>
- <div class="view-dataSpecies-right">
- <div class="view-dataType-title">
- <div class="view-dataType-title-btn">
- <el-button type="success" @click="openDialog()" :disabled="!(currentNode.type == 2)">新增</el-button>
- <el-button type="warning" @click="remove(tableCheckItems)" :disabled="tableCheckItems.length == 0">删除</el-button>
- </div>
- <div class="view-dataType-title-search">
- <el-input placeholder="请输入架次号" v-model="keyWordData" class="input1">
- <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
- </el-input>
- </div>
- </div>
- <div class="view-dataType-table">
- <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options" :pagination="tableRequset"></LTable>
- </div>
- <!-- 添加或修改飞参数据信息对话框 -->
- <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="1000px" :before-close="handleClose">
- <el-form ref="form" :inline="true" :rules="rules" :model="form" label-width="80px">
- <el-row>
- <el-col :span="12">
- <el-form-item label="数据源" prop="source">
- <el-select v-model="form.source" placeholder="请选择数据源" disabled>
- <el-option label="飞参数据" value="1"></el-option>
- <el-option label="MDC数据" value="2"></el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="编目" prop="aircraftId">
- <el-select v-model="form.aircraftId" placeholder="请选择编目" disabled>
- <el-option v-for="item in aircaftCatalogAll" :key="item.aircaftCatalogId" :label="item.aircaftCatalogCode" :value="item.aircaftCatalogId"> </el-option>
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="12">
- <el-form-item label="飞行时间" prop="flightDate">
- <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>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="架次号" prop="sortieNo">
- <el-input disabled v-model="form.sortieNo" placeholder="选择飞行时间自动生成" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="12">
- <el-form-item label="上传飞参数据" label-width="110px" prop="ossId">
- <FileUpload v-model="form.ossId" :limit="1" :fileSize="500" :fileType="['xls', 'xlsx']" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="警告列表导入" label-width="110px">
- <el-upload
- ref="upload"
- :limit="1"
- accept=".xlsx, .xls"
- :headers="upload.headers"
- :action="upload.url + '?updateSupport=' + upload.updateSupport + '&sortieNo=' + form.sortieNo"
- :disabled="upload.isUploading"
- :on-progress="handleFileUploadProgress"
- :on-success="handleFileSuccess"
- :auto-upload="false"
- :file-list="warnFileList"
- >
- <el-button size="small" type="primary">点击上传</el-button>
- <div class="el-upload__tip text-center" slot="tip">
- <div class="el-upload__tip" slot="tip"><el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的数据</div>
- <span>仅允许导入xls、xlsx格式文件。</span>
- <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
- </div>
- </el-upload>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="handleClose">取 消</el-button>
- <el-button type="primary" :loading="submitBtnLoading" @click="submit">确 定</el-button>
- </span>
- </el-dialog>
- </div>
- </div>
- </template>
- <script>
- import { getDataImport, addDataImport, updateDataImport, removeDataImport, importTemplateApi } from '@/api/als/dataImport'
- import { getAircaftCatalogTree } from '@/api/als/sideTree'
- import { getAircaftCatalogAll } from '@/api/als/aircraft'
- import { deepClone, debounce } from '@/utils/index'
- import FileUpload from '@/views/als/components/FileUpload'
- import { flattenTree, download } from '../utils/common'
- import { getItem } from '@/utils/index'
- import { getWarning } from '@/api/als/warning'
- export default {
- name: 'DataImport',
- components: { FileUpload },
- data() {
- // 这里存放数据
- return {
- dialogTitle: '新增',
- dialogVisible: false,
- keyWordData: '',
- aircaftModelIdList: [],
- submitBtnLoading: false,
- currentNodeKey: '',
- currentNode: {},
- menuTreeData: [],
- treeObj: {
- title: '所属机种',
- activityheight: '275px',
- searchIcon: false,
- configure: {
- children: 'children',
- label: 'label'
- }
- },
- rules: {
- source: [{ required: true, message: '数据源不能为空', trigger: 'change' }],
- aircaftModel: [{ required: true, message: '机型不能为空', trigger: 'change' }],
- aircraftId: [{ required: true, message: '编目不能为空', trigger: 'change' }],
- flightDate: [{ required: true, message: '飞行时间不能为空', trigger: 'change' }],
- sortieNo: [{ required: true, message: '飞架次号不能为空', trigger: 'blur' }],
- ossId: [{ required: true, message: '飞参数据不能为空', trigger: 'change' }]
- },
- typeTree: {
- children: 'children',
- label: 'label'
- },
- searchValue: '',
- columns: [
- {
- prop: 'aircraftId',
- label: '编目',
- render: (h, params) => {
- const matchedItem = this.aircaftCatalogAll.find((item) => params.row.aircraftId.trim() === item.aircaftCatalogId.trim())
- if (matchedItem) {
- return h('span', matchedItem.aircaftCatalogCode)
- } else {
- return h('span', {}, '')
- }
- }
- },
- {
- prop: 'sortieNo',
- label: '架次号'
- },
- {
- prop: 'source',
- label: '数据源',
- render: (h, params) => {
- if (params.row.source == 1) {
- return h('span', { class: 'success-state' }, '飞参数据')
- } else {
- return h('span', { class: 'success-state' }, 'MDC数据')
- }
- }
- },
- {
- prop: 'flightDate',
- label: '飞行时间'
- },
- {
- prop: 'ossId',
- label: '文件编号'
- },
- {
- button: true,
- label: '操作',
- width: '240px',
- group: [
- {
- name: '编辑',
- type: 'text',
- round: false,
- plain: false,
- onClick: (row, index, scope) => {
- this.handUpdate(row)
- }
- },
- {
- name: '删除',
- type: 'text',
- round: false,
- plain: false,
- onClick: (row, index, scope) => {
- this.remove([row])
- }
- }
- ]
- }
- ],
- options: {
- stripe: true, // 斑马纹
- mutiSelect: true, // 多选框
- index: false, // 显示序号, 多选则 mutiSelect
- loading: false, // 表格动画
- initTable: false, // 是否一挂载就加载数据
- border: true,
- height: 'calc(100vh - 300px)'
- },
- tableCheckItems: [],
- tableData: [],
- tableRequset: {
- total: 0,
- pageIndex: 1,
- pageSize: 10,
- searchValue: ''
- },
- form: {
- id: '',
- ossId: '',
- source: '1',
- aircraftId: '',
- sortieNo: '',
- flightDate: '',
- status: ''
- },
- debounceFn: debounce(this.fetch, 500),
- aircaftCatalogAll: [],
- upload: {
- // 是否显示弹出层
- open: false,
- // 弹出层标题
- title: '',
- // 是否禁用上传
- isUploading: false,
- // 是否更新已经存在的用户数据
- updateSupport: 0,
- // 设置上传的请求头部
- headers: { Authorization: getItem('token') },
- // 上传的地址
- url: '/api/als/warning/importData'
- },
- warnFileList: [],
- uploadFlag: false
- }
- },
- watch: {
- keyWord() {
- this.tableRequset.pageIndex = 1
- this.debounceFn()
- }
- },
- mounted() {
- this.getAircaftCatalogTreeAPI()
- },
- methods: {
- async getAircaftCatalogTreeAPI(params) {
- try {
- const { data } = await getAircaftCatalogTree(params)
- this.menuTreeData = data
- const getAircaftCatalogAllParams = {
- keyWord: '',
- aircaftModelIdList: []
- }
- const { data: data2 } = await getAircaftCatalogAll(getAircaftCatalogAllParams)
- this.aircaftCatalogAll = data2
- if (data.length) {
- this.currentNodeKey = data[0].id
- this.currentNode = data[0]
- this.aircaftModelIdList = this.getTreeLeafData(data[0]?.children)
- .map((e) => e.id)
- .toString()
- this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
- }
- } catch (error) {}
- },
- async removeDataImportAPI(params) {
- try {
- const { code } = await removeDataImport(params)
- if (code === 200) {
- this.$message({
- type: 'success',
- message: '操作成功!'
- })
- await this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
- this.handleClose()
- }
- } catch (error) {}
- },
- getTreeLeafData(list) {
- const newArr = []
- function getLeaf(data, arr) {
- data.forEach((e) => {
- if (e.type === 2) {
- arr.push(e)
- }
- if (e.children.length) {
- getLeaf(e.children, arr)
- }
- })
- }
- getLeaf(list, newArr)
- return newArr
- },
- async getDataImportAPI(params) {
- if (this.$refs.table) this.$refs.table.clearSelection()
- const { keyWord } = this
- const { pageSize, pageIndex } = this.tableRequset
- const {
- data: { list, total }
- } = await getDataImport({ pageSize, pageNum: pageIndex, ...params, source: 1 })
- this.tableData = list
- this.tableRequset.total = total
- },
- fetch() {
- this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
- },
- async searchClick() {
- this.getDataImportAPI({ aircraftId: this.aircaftModelIdList, sortieNo: this.keyWordData })
- },
- async addDataImportAPI() {
- try {
- delete this.form.aircaftModelName
- const { code } = await addDataImport({ ...this.form })
- if (code === 200) {
- this.$message({
- type: 'success',
- message: '操作成功!'
- })
- this.uploadFlag = true
- this.handleClose()
- this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
- this.submitBtnLoading = false
- }
- } catch (error) {
- this.submitBtnLoading = false
- }
- },
- async updateDataImportAPI() {
- try {
- const { code } = await updateDataImport({ ...this.form })
- if (code === 200) {
- this.$message({
- type: 'success',
- message: '操作成功!'
- })
- this.handleClose()
- this.submitBtnLoading = false
- this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
- }
- } catch (error) {
- this.submitBtnLoading = false
- }
- },
- treeNodeClick(data) {
- this.$refs.table.clearSelection()
- this.currentNodeKey = data.id
- this.currentNode = data
- this.aircaftModelIdList = this.getTreeLeafData(data.children.length ? data.children : [data])
- .map((e) => e.id)
- .toString()
- if (!this.aircaftModelIdList) {
- this.aircaftModelIdList = '#'
- }
- this.getDataImportAPI({ aircraftId: this.aircaftModelIdList })
- },
- openDialog() {
- this.dialogTitle = '新增'
- this.dialogVisible = true
- this.form.aircraftId = this.currentNodeKey
- this.form.aircaftModel = this.currentNode.parentId
- },
- handleClose() {
- this.dialogVisible = false
- this.form = {
- id: '',
- ossId: '',
- source: '1',
- sortieNo: '',
- aircraftId: '',
- flightDate: '',
- status: ''
- }
- },
- async handUpdate(row) {
- this.dialogTitle = '编辑'
- this.form = deepClone(row)
- // const {
- // data: { list, total }
- // }=await getWarning({ sortieNo: row.SortieNo })
- // if(total!==0){
- // }
- // console.log('this.form', this.form)
- this.dialogVisible = true
- },
- submit() {
- this.$refs['form'].validate((valid) => {
- if (valid) {
- switch (this.dialogTitle) {
- case '编辑':
- this.submitBtnLoading = true
- this.updateDataImportAPI()
- this.submitFileForm()
- break
- case '新增':
- this.submitBtnLoading = true
- this.addDataImportAPI()
- this.submitFileForm()
- break
- }
- }
- })
- },
- selection(val) {
- this.tableCheckItems = val
- },
- remove(row) {
- this.$confirm('是否删除该数据', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(() => {
- this.removeDataImportAPI(row.map((e) => e.id))
- })
- .catch(() => {})
- },
- flightDateChange() {
- this.form.sortieNo = this.getTime('JC')
- // this.form.sortieNo = this.getTime() + '-' + obj?.model
- },
- getTime(prefix) {
- const now = new Date()
- const year = now.getFullYear()
- const month = ('0' + (now.getMonth() + 1)).slice(-2)
- const day = ('0' + now.getDate()).slice(-2)
- const hours = ('0' + now.getHours()).slice(-2)
- const minutes = ('0' + now.getMinutes()).slice(-2)
- const seconds = ('0' + now.getSeconds()).slice(-2)
- const dateString = `${year}${month}${day}${hours}${minutes}${seconds}` // 返回格式化的单号
- return `${prefix}-${dateString}`
- },
- /** 导入按钮操作 */
- handleImport() {
- this.upload.title = '警告列表导入'
- this.upload.open = true
- },
- /** 下载模板操作 */
- importTemplate() {
- useDownload(importTemplateApi, 'warning_template', {}, '.xlsx')
- },
- // 文件上传中处理
- handleFileUploadProgress(event, file, fileList) {
- this.upload.isUploading = true
- },
- // 文件上传成功处理
- handleFileSuccess(response, file, fileList) {
- if (this.uploadFlag) {
- this.upload.open = false
- this.upload.isUploading = false
- this.$refs.upload.clearFiles()
- this.submitBtnLoading = false
- }
- // this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', { dangerouslyUseHTMLString: true })
- },
- // 提交上传文件
- submitFileForm() {
- this.$refs.upload.submit()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import '../index.scss';
- </style>
|