index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. <el-dropdown split-button type="primary" style="margin-left: 10px" trigger="click" @command="handleExport">
  12. 更多
  13. <el-dropdown-menu slot="dropdown">
  14. <el-dropdown-item command="importOperation">导入</el-dropdown-item>
  15. <el-dropdown-item command="allExport" :disabled="tableData.length == 0">导出</el-dropdown-item>
  16. <el-dropdown-item command="downloadTemplate">下载数据模板</el-dropdown-item>
  17. </el-dropdown-menu>
  18. </el-dropdown>
  19. </div>
  20. <div class="view-dataType-title-search">
  21. <el-input placeholder="请输入关键字" v-model="keyWord" class="input1">
  22. <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
  23. </el-input>
  24. </div>
  25. </div>
  26. <div class="view-dataType-table">
  27. <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options" :pagination="tableRequset"></LTable>
  28. </div>
  29. <!-- 添加或修改定检任务对话框 -->
  30. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
  31. <el-form ref="form" :model="form" label-width="80px">
  32. <el-form-item label="机型" prop="aircraftModel">
  33. <el-select v-model="form.aircraftModel" placeholder="请选择机型" disabled>
  34. <el-option v-for="item in aircaftModelAll" :key="item.aircaftModelId" :label="item.aircaftModelName" :value="item.aircaftModelId"> </el-option>
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item label="编目" prop="aircraftId">
  38. <el-select v-model="form.aircraftId" placeholder="请选择编目" disabled>
  39. <el-option v-for="item in aircaftCatalogAll" :key="item.aircaftCatalogId" :label="item.aircaftCatalogCode" :value="item.aircaftCatalogId"> </el-option>
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item label="检查项名称" prop="name">
  43. <el-input v-model="form.name" placeholder="请输入检查项名称" />
  44. </el-form-item>
  45. <el-form-item label="专业" prop="specialty">
  46. <el-input v-model="form.specialty" placeholder="请输入专业" />
  47. </el-form-item>
  48. <el-form-item label="任务编码" prop="taskCode">
  49. <el-input v-model="form.taskCode" placeholder="请输入任务编码" />
  50. </el-form-item>
  51. <el-form-item label="周期" prop="periodTime">
  52. <el-input v-model="form.periodTime" placeholder="请输入周期" />
  53. </el-form-item>
  54. <!-- <el-form-item label="剩余时间" prop="remainTime">
  55. <el-input v-model="form.remainTime" placeholder="请输入剩余时间" />
  56. </el-form-item> -->
  57. <el-form-item label="负责人" prop="headName">
  58. <el-input v-model="form.headName" placeholder="请输入负责人" />
  59. </el-form-item>
  60. <el-form-item label="系统" prop="systemName">
  61. <el-input v-model="form.systemName" placeholder="请输入系统" />
  62. </el-form-item>
  63. <el-form-item label="任务内容" prop="contents">
  64. <el-input v-model="form.contents" placeholder="请输入任务内容" />
  65. </el-form-item>
  66. <el-form-item label="备注" prop="remark">
  67. <el-input v-model="form.remark" placeholder="请输入备注" />
  68. </el-form-item>
  69. </el-form>
  70. <span slot="footer" class="dialog-footer">
  71. <el-button @click="handleClose">取 消</el-button>
  72. <el-button type="primary" @click="submit">确 定</el-button>
  73. </span>
  74. </el-dialog>
  75. <!-- 导入 -->
  76. <ImportDialog ref="ImportDialog" @submitCallBack="ImportDialogCallBack" />
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import { getSmTask, addSmTask, updateSmTask, removeSmTask, downLoadSmTask, exportSmTask } from '@/api/als/smTask'
  82. import { deepClone, debounce } from '@/utils/index'
  83. import { getAircaftCatalogTree } from '@/api/als/sideTree'
  84. import { getAircaftModelAll, getAircaftCatalogAll } from '@/api/als/aircraft'
  85. import { flattenTree } from '../utils/common'
  86. import ImportDialog from './importDialog/index.vue'
  87. export default {
  88. name: 'SmTask',
  89. components: { ImportDialog },
  90. data() {
  91. // 这里存放数据
  92. return {
  93. dialogTitle: '新增',
  94. dialogVisible: false,
  95. keyWord: '',
  96. aircaftModelIdList: [],
  97. currentNodeKey: '',
  98. currentNode: {},
  99. menuTreeData: [],
  100. treeObj: {
  101. title: '所属机种',
  102. activityheight: '275px',
  103. searchIcon: false,
  104. configure: {
  105. children: 'children',
  106. label: 'label'
  107. }
  108. },
  109. typeTree: {
  110. children: 'children',
  111. label: 'label'
  112. },
  113. searchValue: '',
  114. columns: [
  115. {
  116. prop: 'aircraftModel',
  117. label: '机型',
  118. render: (h, params) => {
  119. const matchedItem = this.aircaftModelAll.find((item) => params.row.aircraftModel === item.aircaftModelId)
  120. if (matchedItem) {
  121. return h('span', matchedItem.aircaftModelName)
  122. } else {
  123. return h('span', params.row.aircraftModel)
  124. }
  125. }
  126. },
  127. {
  128. prop: 'aircraftId',
  129. label: '编目',
  130. render: (h, params) => {
  131. const matchedItem = this.aircaftCatalogAll.find((item) => params.row.aircraftId.trim() === item.aircaftCatalogId.trim())
  132. if (matchedItem) {
  133. return h('span', matchedItem.aircaftCatalogCode)
  134. } else {
  135. return h('span', params.row.aircraftId)
  136. }
  137. }
  138. },
  139. {
  140. prop: 'name',
  141. label: '检查项名称'
  142. },
  143. {
  144. prop: 'specialty',
  145. label: '专业'
  146. },
  147. {
  148. prop: 'taskCode',
  149. label: '任务编码'
  150. },
  151. {
  152. prop: 'periodTime',
  153. label: '周期'
  154. },
  155. // {
  156. // prop: 'remainTime',
  157. // label: '剩余时间'
  158. // },
  159. {
  160. prop: 'headName',
  161. label: '负责人'
  162. },
  163. {
  164. prop: 'systemName',
  165. label: '系统'
  166. },
  167. {
  168. prop: 'contents',
  169. label: '任务内容'
  170. },
  171. // {
  172. // prop: 'status',
  173. // label: '状态',
  174. // render: (h, params) => {
  175. // if (params.row.status == 0) {
  176. // return h('span', { class: 'warning-state' }, '未分配')
  177. // } else {
  178. // return h('span', { class: 'success-state' }, '已分配')
  179. // }
  180. // }
  181. // },
  182. {
  183. prop: 'remark',
  184. label: '备注'
  185. },
  186. {
  187. button: true,
  188. label: '操作',
  189. width: '240px',
  190. group: [
  191. {
  192. name: '编辑',
  193. type: 'text',
  194. round: false,
  195. plain: false,
  196. onClick: (row, index, scope) => {
  197. this.handUpdate(row)
  198. }
  199. },
  200. {
  201. name: '查看',
  202. type: 'text',
  203. round: false,
  204. plain: false,
  205. onClick: (row, index, scope) => {
  206. this.checkDetails(row)
  207. }
  208. },
  209. {
  210. name: '删除',
  211. type: 'text',
  212. round: false,
  213. plain: false,
  214. onClick: (row, index, scope) => {
  215. this.remove([row])
  216. }
  217. }
  218. ]
  219. }
  220. ],
  221. options: {
  222. stripe: true, // 斑马纹
  223. mutiSelect: true, // 多选框
  224. index: false, // 显示序号, 多选则 mutiSelect
  225. loading: false, // 表格动画
  226. initTable: false, // 是否一挂载就加载数据
  227. border: true,
  228. height: 'calc(100vh - 300px)'
  229. },
  230. tableCheckItems: [],
  231. tableData: [],
  232. tableRequset: {
  233. total: 0,
  234. pageIndex: 1,
  235. pageSize: 10,
  236. searchValue: ''
  237. },
  238. form: {
  239. id: '',
  240. aircraftId: '',
  241. aircraftModel: '',
  242. name: '',
  243. specialty: '',
  244. taskCode: '',
  245. periodTime: '',
  246. remainTime: '',
  247. headName: '',
  248. systemName: '',
  249. contents: '',
  250. status: '',
  251. remark: ''
  252. },
  253. debounceFn: debounce(this.fetch, 500),
  254. aircaftModelAll: [],
  255. aircaftCatalogAll: []
  256. }
  257. },
  258. watch: {
  259. keyWord() {
  260. this.tableRequset.pageIndex = 1
  261. this.debounceFn()
  262. }
  263. },
  264. mounted() {
  265. this.getAircaftCatalogTreeAPI()
  266. },
  267. methods: {
  268. async getAircaftCatalogTreeAPI(params) {
  269. const { data } = await getAircaftCatalogTree(params)
  270. this.menuTreeData = data
  271. const getAircaftModelAllParams = {
  272. aircaftTypeCode: '',
  273. aircaftTypeId: '',
  274. queryParam: ''
  275. }
  276. const { data: data1 } = await getAircaftModelAll(getAircaftModelAllParams)
  277. this.aircaftModelAll = data1
  278. if (data.length) {
  279. this.currentNodeKey = data[0].id
  280. this.currentNode = data[0]
  281. this.aircaftModelIdList = String(this.getTreeLeafData(data[0]?.children).map((e) => e.id))
  282. this.getSmTaskAPI({ aircraftId: this.aircaftModelIdList })
  283. }
  284. const { data: data2 } = await getAircaftCatalogAll({
  285. keyWord: '',
  286. aircaftModelIdList: []
  287. })
  288. this.aircaftCatalogAll = flattenTree(data2)
  289. },
  290. async removeSmTaskAPI(params) {
  291. try {
  292. const { code } = await removeSmTask(params)
  293. if (code == 200) {
  294. this.$message({
  295. type: 'success',
  296. message: '操作成功!'
  297. })
  298. await this.getSmTaskAPI({ aircraftId: this.aircaftModelIdList })
  299. this.handleClose()
  300. }
  301. } catch (error) {}
  302. },
  303. getTreeLeafData(list) {
  304. const newArr = []
  305. function getLeaf(data, arr) {
  306. data.forEach((e) => {
  307. if (e.type === 2) {
  308. arr.push(e)
  309. }
  310. if (e.children.length) {
  311. getLeaf(e.children, arr)
  312. }
  313. })
  314. }
  315. getLeaf(list, newArr)
  316. return newArr
  317. },
  318. async getSmTaskAPI(params) {
  319. if (this.$refs.table) this.$refs.table.clearSelection()
  320. const { keyWord } = this
  321. const { pageSize, pageIndex } = this.tableRequset
  322. const {
  323. data: { list, total }
  324. } = await getSmTask({ pageSize, pageNum: pageIndex, ...params })
  325. this.tableData = list
  326. this.tableRequset.total = total
  327. },
  328. fetch() {
  329. this.getSmTaskAPI({ aircraftId: this.aircaftModelIdList })
  330. },
  331. searchClick() {
  332. this.getSmTaskAPI({ aircraftId: this.aircaftModelIdList })
  333. },
  334. async addSmTaskAPI() {
  335. try {
  336. delete this.form.aircaftModelName
  337. const { code } = await addSmTask({ ...this.form })
  338. if (code === 200) {
  339. this.$message({
  340. type: 'success',
  341. message: '操作成功!'
  342. })
  343. this.handleClose()
  344. this.getSmTaskAPI({ aircraftId: this.aircaftModelIdList })
  345. }
  346. } catch (error) {}
  347. },
  348. async updateSmTaskAPI() {
  349. try {
  350. const { code } = await updateSmTask({ ...this.form })
  351. if (code === 200) {
  352. this.$message({
  353. type: 'success',
  354. message: '操作成功!'
  355. })
  356. this.handleClose()
  357. this.getSmTaskAPI({ aircraftId: this.aircaftModelIdList })
  358. }
  359. } catch (error) {}
  360. },
  361. async treeNodeClick(data) {
  362. this.$refs.table.clearSelection()
  363. this.currentNodeKey = this.form.aircraftId = data.id
  364. console.log(data)
  365. this.currentNode = data
  366. this.aircaftModelIdList = String(this.getTreeLeafData(data.children.length ? data.children : [data]).map((e) => e.id))
  367. this.getSmTaskAPI({ aircraftId: this.aircaftModelIdList })
  368. },
  369. openDialog() {
  370. this.dialogTitle = '新增'
  371. this.dialogVisible = true
  372. this.form.aircraftModel = this.currentNode.parentId
  373. this.form.aircraftId = this.currentNodeKey
  374. this.form.status = 0
  375. },
  376. handleClose() {
  377. this.dialogVisible = false
  378. this.form = {
  379. id: '',
  380. aircraftId: '',
  381. aircraftModel: '',
  382. name: '',
  383. specialty: '',
  384. taskCode: '',
  385. periodTime: '',
  386. remainTime: '',
  387. headName: '',
  388. systemName: '',
  389. contents: '',
  390. status: '',
  391. remark: ''
  392. }
  393. },
  394. handUpdate(row) {
  395. this.dialogTitle = '编辑'
  396. this.form = deepClone(row)
  397. this.dialogVisible = true
  398. },
  399. submit() {
  400. switch (this.dialogTitle) {
  401. case '编辑':
  402. this.updateSmTaskAPI()
  403. break
  404. case '新增':
  405. this.addSmTaskAPI()
  406. break
  407. }
  408. },
  409. selection(val) {
  410. this.tableCheckItems = val
  411. },
  412. remove(row) {
  413. this.$confirm('是否删除该数据', '提示', {
  414. confirmButtonText: '确定',
  415. cancelButtonText: '取消',
  416. type: 'warning'
  417. })
  418. .then(() => {
  419. this.removeSmTaskAPI(row.map((e) => e.id))
  420. })
  421. .catch(() => {})
  422. },
  423. checkDetails(row) {
  424. // this.$router.push({ name: 'SMTaskDetails', params: { smTaskId: row.id } })
  425. this.$router.push({
  426. name: 'SMTaskDetails',
  427. query: {
  428. smTaskId: row.id
  429. }
  430. })
  431. },
  432. //更多按钮
  433. handleExport(type) {
  434. this[type]()
  435. },
  436. //导入
  437. importOperation() {
  438. this.$refs.ImportDialog.triggerDialog()
  439. },
  440. //导入回写
  441. ImportDialogCallBack() {
  442. this.getAircaftCatalogTreeAPI()
  443. },
  444. //导出全部
  445. async allExport() {
  446. // const params = {
  447. // queryParam: this.searchValue
  448. // }
  449. await exportSmTask({})
  450. },
  451. //下载模板
  452. async downloadTemplate() {
  453. await downLoadSmTask()
  454. }
  455. }
  456. }
  457. </script>
  458. <style lang="scss" scoped>
  459. @import '../index.scss';
  460. </style>
  461. @/api/als/smTask