index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 == 1 && currentNode.children.length == 0)">新增</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="600px" :before-close="handleClose">
  23. <el-form ref="form" :model="form" label-width="80px">
  24. <el-form-item label="上级名称" prop="conCode">
  25. <treeselect v-model="form.parentId" :normalizer="normalizer" :options="tableData" :show-count="true" placeholder="选择上级名称" />
  26. <!-- <el-input v-model="form.conCode" placeholder="请输入构型编码" /> -->
  27. </el-form-item>
  28. <el-form-item label="构型编码" prop="conCode">
  29. <el-input v-model="form.conCode" placeholder="请输入构型编码" />
  30. </el-form-item>
  31. <el-form-item label="产品名称" prop="name">
  32. <el-input v-model="form.name" placeholder="请输入产品名称" />
  33. </el-form-item>
  34. <el-form-item label="规格型号" prop="specsModel">
  35. <el-input v-model="form.specsModel" placeholder="请输入规格型号" />
  36. </el-form-item>
  37. <el-form-item label="图号" prop="drawingNumber">
  38. <el-input v-model="form.drawingNumber" placeholder="请输入图号" />
  39. </el-form-item>
  40. <el-form-item label="供应商" prop="supplier">
  41. <el-input v-model="form.supplier" placeholder="请输入供应商" />
  42. </el-form-item>
  43. <el-form-item label="描述" prop="remarks">
  44. <el-input type="textarea" :rows="2" v-model="form.remarks" placeholder="请输入描述" />
  45. </el-form-item>
  46. </el-form>
  47. <span slot="footer" class="dialog-footer">
  48. <el-button @click="handleClose">取 消</el-button>
  49. <el-button type="primary" @click="submit">确 定</el-button>
  50. </span>
  51. </el-dialog>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { getAirConfiguration, addAirConfiguration, updateAirConfiguration, removeAirConfiguration } from '@/api/als/airConfiguration'
  57. import { getAircaftCatalogTree, getAircaftTypeAndModelTree } from '@/api/als/sideTree'
  58. import { deepClone, debounce } from '@/utils/index'
  59. import { getAircaftModelAll } from '@/api/als/aircraft'
  60. import { handleTree } from '../utils/common'
  61. import Treeselect from '@riophae/vue-treeselect'
  62. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  63. export default {
  64. name: 'AirConfiguration',
  65. components: { Treeselect },
  66. data() {
  67. // 这里存放数据
  68. return {
  69. dialogTitle: '新增',
  70. dialogVisible: false,
  71. keyWordData: '',
  72. aircaftModelIdList: [],
  73. currentNodeKey: '',
  74. currentNode: {},
  75. menuTreeData: [],
  76. treeObj: {
  77. title: '所属机种',
  78. activityheight: '275px',
  79. searchIcon: false,
  80. configure: {
  81. children: 'children',
  82. label: 'label'
  83. }
  84. },
  85. typeTree: {
  86. children: 'children',
  87. label: 'label'
  88. },
  89. searchValue: '',
  90. columns: [
  91. // { prop: 'id', label: '唯一ID' },
  92. {
  93. prop: 'name',
  94. label: '产品名称',
  95. align: 'left'
  96. },
  97. {
  98. prop: 'conCode',
  99. label: '构型编码'
  100. },
  101. {
  102. prop: 'aircraftType',
  103. label: '机型',
  104. render: (h, params) => {
  105. const matchedItem = this.aircaftModelAll.find((item) => params.row.aircraftType === item.aircaftModelId)
  106. if (matchedItem) {
  107. return h('span', matchedItem.aircaftModelName)
  108. } else {
  109. return h('span', {}, '')
  110. }
  111. }
  112. },
  113. {
  114. prop: 'specsModel',
  115. label: '规格型号'
  116. },
  117. {
  118. prop: 'drawingNumber',
  119. label: '图号'
  120. },
  121. {
  122. prop: 'supplier',
  123. label: '供应商'
  124. },
  125. {
  126. prop: 'remarks',
  127. label: '描述'
  128. },
  129. {
  130. button: true,
  131. label: '操作',
  132. width: '240px',
  133. group: [
  134. {
  135. name: '编辑',
  136. type: 'text',
  137. round: false,
  138. plain: false,
  139. onClick: (row, index, scope) => {
  140. this.handUpdate(row)
  141. }
  142. },
  143. {
  144. name: '删除',
  145. type: 'text',
  146. round: false,
  147. plain: false,
  148. onClick: (row, index, scope) => {
  149. this.remove([row])
  150. }
  151. }
  152. ]
  153. }
  154. ],
  155. options: {
  156. stripe: true, // 斑马纹
  157. mutiSelect: true, // 多选框
  158. index: false, // 显示序号, 多选则 mutiSelect
  159. loading: false, // 表格动画
  160. initTable: false, // 是否一挂载就加载数据
  161. border: true,
  162. height: 'calc(100vh - 300px)',
  163. treeProps: {
  164. children: 'children',
  165. hasChildren: 'hasChildren'
  166. }
  167. },
  168. tableCheckItems: [],
  169. tableData: [],
  170. tableRequset: {
  171. total: 0,
  172. pageIndex: 1,
  173. pageSize: 10,
  174. searchValue: ''
  175. },
  176. form: {
  177. id: '',
  178. aircraftType: '',
  179. conCode: '',
  180. name: '',
  181. specsModel: '',
  182. drawingNumber: '',
  183. supplier: '',
  184. remarks: '',
  185. tenantId: '',
  186. delFlag: '',
  187. version: '',
  188. createdBy: '',
  189. createdTime: '',
  190. updatedBy: '',
  191. updatedTime: ''
  192. },
  193. debounceFn: debounce(this.fetch, 500),
  194. aircaftModelAll: []
  195. }
  196. },
  197. watch: {
  198. keyWord() {
  199. this.tableRequset.pageIndex = 1
  200. this.debounceFn()
  201. }
  202. },
  203. mounted() {
  204. this.getAircaftCatalogTreeAPI()
  205. },
  206. methods: {
  207. async getAircaftCatalogTreeAPI(params) {
  208. const { data } = await getAircaftTypeAndModelTree(params)
  209. this.menuTreeData = data
  210. const getAircaftModelAllParams = {
  211. aircaftTypeCode: '',
  212. aircaftTypeId: '',
  213. queryParam: ''
  214. }
  215. const { data: data1 } = await getAircaftModelAll(getAircaftModelAllParams)
  216. this.aircaftModelAll = data1
  217. if (data.length) {
  218. this.currentNodeKey = data[0].id
  219. this.currentNode = data[0]
  220. this.aircaftModelIdList = this.getTreeLeafData(data[0]?.children)
  221. .map((e) => e.id)
  222. .toString()
  223. this.getAirConfigurationAPI({ aircraftType: this.aircaftModelIdList })
  224. // this.getAirConfigurationAPI()
  225. }
  226. },
  227. normalizer(node) {
  228. if (node.children && !node.children.length) {
  229. delete node.children
  230. }
  231. return {
  232. id: node.id,
  233. label: node.name,
  234. children: node.children
  235. }
  236. },
  237. async removeAirConfigurationAPI(params) {
  238. try {
  239. const { code } = await removeAirConfiguration(params)
  240. if (code === 200) {
  241. this.$message({
  242. type: 'success',
  243. message: '操作成功!'
  244. })
  245. await this.getAirConfigurationAPI({ aircraftType: this.aircaftModelIdList })
  246. this.handleClose()
  247. }
  248. } catch (error) {}
  249. },
  250. getTreeLeafData(list) {
  251. const newArr = []
  252. function getLeaf(data, arr) {
  253. data.forEach((e) => {
  254. if (e.type === 1) {
  255. arr.push(e)
  256. }
  257. if (e.children.length) {
  258. getLeaf(e.children, arr)
  259. }
  260. })
  261. }
  262. getLeaf(list, newArr)
  263. return newArr
  264. },
  265. async getAirConfigurationAPI(params) {
  266. if (this.$refs.table) this.$refs.table.clearSelection()
  267. const { keyWord } = this
  268. const { pageSize, pageIndex } = this.tableRequset
  269. const { data, code } = await getAirConfiguration({ pageSize, pageNum: pageIndex, ...params })
  270. if (code === 200) {
  271. this.tableData = []
  272. if (!(this.currentNode.type == 1 && this.currentNode.children.length == 0)) {
  273. if (data?.length !== 0) {
  274. const allData = handleTree(data, 'id')
  275. this.tableData = allData
  276. }
  277. } else {
  278. const menu = { id: 1, aircraftType: this.currentNode.id, name: '整机', children: [] }
  279. menu.children = handleTree(data, 'id')
  280. this.tableData.push(menu)
  281. }
  282. }
  283. },
  284. fetch() {
  285. this.getAirConfigurationAPI({ aircraftType: this.aircaftModelIdList })
  286. },
  287. searchClick() {
  288. this.getAirConfigurationAPI({ aircraftType: this.aircaftModelIdList, name: this.keyWordData })
  289. },
  290. async addAirConfigurationAPI() {
  291. try {
  292. delete this.form.aircaftModelName
  293. const { code } = await addAirConfiguration({ ...this.form })
  294. if (code === 200) {
  295. this.$message({
  296. type: 'success',
  297. message: '操作成功!'
  298. })
  299. this.getAirConfigurationAPI({ aircraftType: this.aircaftModelIdList })
  300. }
  301. } catch (error) {}
  302. },
  303. async updateAirConfigurationAPI() {
  304. try {
  305. const { code } = await updateAirConfiguration({ ...this.form })
  306. if (code === 200) {
  307. this.$message({
  308. type: 'success',
  309. message: '操作成功!'
  310. })
  311. this.getAirConfigurationAPI({ aircraftType: this.aircaftModelIdList })
  312. }
  313. } catch (error) {}
  314. },
  315. treeNodeClick(data) {
  316. this.$refs.table.clearSelection()
  317. this.currentNodeKey = data.id
  318. this.currentNode = data
  319. console.log('this.currentNode', this.currentNode)
  320. this.aircaftModelIdList = this.getTreeLeafData(data.children.length ? data.children : [data])
  321. .map((e) => e.id)
  322. .toString()
  323. this.getAirConfigurationAPI({ aircraftType: this.aircaftModelIdList })
  324. },
  325. openDialog() {
  326. this.dialogTitle = '新增'
  327. this.dialogVisible = true
  328. this.form.aircraftType = this.currentNodeKey
  329. },
  330. handleClose() {
  331. this.dialogVisible = false
  332. this.form = {
  333. id: '',
  334. aircraftType: '',
  335. conCode: '',
  336. name: '',
  337. specsModel: '',
  338. drawingNumber: '',
  339. supplier: '',
  340. remarks: '',
  341. tenantId: '',
  342. delFlag: '',
  343. version: '',
  344. createdBy: '',
  345. createdTime: '',
  346. updatedBy: '',
  347. updatedTime: ''
  348. }
  349. },
  350. handUpdate(row) {
  351. this.dialogTitle = '编辑'
  352. this.form = deepClone(row)
  353. this.dialogVisible = true
  354. },
  355. submit() {
  356. switch (this.dialogTitle) {
  357. case '编辑':
  358. this.updateAirConfigurationAPI()
  359. this.handleClose()
  360. break
  361. case '新增':
  362. this.addAirConfigurationAPI()
  363. this.handleClose()
  364. break
  365. }
  366. },
  367. selection(val) {
  368. this.tableCheckItems = val
  369. },
  370. remove(row) {
  371. this.$confirm('是否删除该数据', '提示', {
  372. confirmButtonText: '确定',
  373. cancelButtonText: '取消',
  374. type: 'warning'
  375. })
  376. .then(() => {
  377. this.removeAirConfigurationAPI(row.map((e) => e.id))
  378. })
  379. .catch(() => {})
  380. }
  381. }
  382. }
  383. </script>
  384. <style lang="scss" scoped>
  385. @import '../index.scss';
  386. </style>