recording-details.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <div class="production">
  3. <el-dialog title="生产记录详情"
  4. width="70%"
  5. :close-on-click-modal="false"
  6. :visible.sync="visible">
  7. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
  8. <el-row class="my-row" style="height: 350px; background-color: #efefef;">
  9. <super-flow
  10. v-if="visible"
  11. ref="superFlow"
  12. :node-list="nodeList"
  13. :link-list="linkList"
  14. :graph-menu="graphMenuList"
  15. :node-menu="nodeMenuList"
  16. :link-menu="linkMenuList"
  17. :link-desc="linkDesc">
  18. </super-flow>
  19. </el-row>
  20. </el-form>
  21. <span slot="footer" class="dialog-footer">
  22. <el-button @click="visible = false">取消</el-button>
  23. <el-button type="primary" @click="dataFormSubmit()">确认提交</el-button>
  24. </span>
  25. </el-dialog>
  26. <el-dialog
  27. :title="drawerConf.title"
  28. :visible.sync="drawerConf.visible"
  29. :close-on-click-modal="false"
  30. width="500px">
  31. <el-form
  32. @keyup.native.enter="settingSubmit"
  33. @submit.native.prevent
  34. v-show="drawerConf.type === drawerType.node"
  35. ref="nodeSetting"
  36. :rules="dataRule1"
  37. :model="nodeSetting">
  38. <el-row class="my-row">
  39. <el-col :span="24">
  40. <el-form-item
  41. label="节点名称"
  42. prop="name">
  43. <el-input
  44. v-model="nodeSetting.name"
  45. placeholder="请输入节点名称"
  46. maxlength="30"
  47. disabled>
  48. </el-input>
  49. </el-form-item>
  50. </el-col>
  51. </el-row>
  52. <el-row class="my-row" >
  53. <el-col :span="24" v-if="drawerConf.prop !== 'end'">
  54. <el-form-item
  55. label="操作人员"
  56. prop="operatorIds">
  57. <el-select
  58. v-model="nodeSetting.operatorIds"
  59. multiple
  60. style="width:100%"
  61. placeholder="请选择">
  62. <el-option
  63. v-for="item in operatorList"
  64. :key="item.userId"
  65. :label="item.name"
  66. :value="item.userId">
  67. </el-option>
  68. </el-select>
  69. </el-form-item>
  70. </el-col>
  71. </el-row>
  72. </el-form>
  73. <span
  74. slot="footer"
  75. class="dialog-footer">
  76. <el-button
  77. @click="drawerConf.cancel">
  78. 取 消
  79. </el-button>
  80. <el-button
  81. type="primary"
  82. @click="settingSubmit">
  83. 确 定
  84. </el-button>
  85. </span>
  86. </el-dialog>
  87. </div>
  88. </template>
  89. <script>
  90. import { getStepId } from '@/api/crafts'
  91. import { getMonitoringDetail } from '@/api/production'
  92. import { uuid } from '../common/vue-super-flow/utils'
  93. const drawerType = {
  94. node: 0,
  95. link: 1
  96. }
  97. export default {
  98. name: 'recording-details',
  99. data () {
  100. return {
  101. mouldId: '',
  102. visible: false,
  103. dataForm: {},
  104. drawerType,
  105. operatorList: [],
  106. operatorIds: [],
  107. productList: [],
  108. display: false,
  109. drawerConf: {
  110. title: '',
  111. visible: false,
  112. prop: '',
  113. type: null,
  114. info: null,
  115. open: (type, info) => {
  116. if (info.meta.workTypeId && info.meta.prop !== 'end') {
  117. this.getOperatorList(info.meta.workTypeId);
  118. }
  119. const conf = this.drawerConf
  120. conf.visible = true
  121. conf.type = type
  122. conf.info = info
  123. if (conf.type === drawerType.node) {
  124. conf.title = '节点'
  125. conf.prop = info.meta.prop
  126. if (this.$refs.nodeSetting) this.$refs.nodeSetting.resetFields()
  127. this.$set(this.nodeSetting, 'name', info.meta.name)
  128. this.$set(this.nodeSetting, 'desc', info.meta.desc)
  129. // this.$set(this.nodeSetting, 'prop', info.meta.prop)
  130. this.$set(this.nodeSetting, 'type', info.meta.type)
  131. this.$set(this.nodeSetting, 'workTypeId', info.meta.workTypeId)
  132. this.$set(this.nodeSetting, 'operatorIds', info.meta.operatorIds)
  133. } else {
  134. conf.title = '连线'
  135. if (this.$refs.linkSetting) this.$refs.linkSetting.resetFields()
  136. // this.$set(this.linkSetting, 'desc', info.meta ? info.meta.desc : '')
  137. }
  138. },
  139. cancel: () => {
  140. this.drawerConf.visible = false
  141. if (this.drawerConf.type === drawerType.node) {
  142. this.$refs.nodeSetting.clearValidate()
  143. } else {
  144. this.$refs.linkSetting.clearValidate()
  145. }
  146. }
  147. },
  148. linkSetting: {
  149. desc: ''
  150. },
  151. nodeSetting: {
  152. name: '',
  153. desc: '',
  154. type: 1,
  155. workTypeId: ''
  156. },
  157. origin: [100, 100],
  158. nodeList: [],
  159. linkList: [],
  160. graphMenuList: [
  161. [
  162. {
  163. label: '开始节点',
  164. disable: true,
  165. selected: async (graph, coordinate) => {
  166. const start = graph.nodeList.find(node => node.meta.prop === 'start')
  167. let id = ''
  168. await getStepId().then(({ data }) => {
  169. id = data.data.stepId
  170. })
  171. if (!start) {
  172. graph.addNode({
  173. width: 90,
  174. height: 50,
  175. coordinate: coordinate,
  176. id: id,
  177. meta: {
  178. prop: 'start',
  179. name: '开始节点'
  180. }
  181. })
  182. }
  183. }
  184. },
  185. {
  186. label: '节点',
  187. disable: true,
  188. selected: async (graph, coordinate) => {
  189. let id = ''
  190. await getStepId().then(({ data }) => {
  191. id = data.data.stepId
  192. })
  193. graph.addNode({
  194. width: 120,
  195. height: 70,
  196. coordinate: coordinate,
  197. id: id,
  198. meta: {
  199. prop: 'condition',
  200. name: '节点名称'
  201. }
  202. })
  203. }
  204. },
  205. {
  206. label: '结束节点',
  207. disable: true,
  208. selected: async (graph, coordinate) => {
  209. let id = ''
  210. await getStepId().then(({ data }) => {
  211. id = data.data.stepId
  212. })
  213. graph.addNode({
  214. width: 90,
  215. height: 50,
  216. coordinate: coordinate,
  217. id: id,
  218. meta: {
  219. prop: 'end',
  220. name: '结束节点'
  221. }
  222. })
  223. }
  224. }
  225. ],
  226. [
  227. {
  228. label: '完成',
  229. selected: (graph, coordinate) => {
  230. graph.selectAll()
  231. this.datas = graph
  232. console.log(graph)
  233. }
  234. }
  235. ]
  236. ],
  237. nodeMenuList: [
  238. // [
  239. // {
  240. // label: '删除',
  241. // disable: true,
  242. // hidden (node) {
  243. // return node.meta.prop === 'start'
  244. // },
  245. // selected (node, coordinate) {
  246. // node.remove()
  247. // }
  248. // }
  249. // ],
  250. // [
  251. // {
  252. // label: '编辑',
  253. // selected: (node, coordinate) => {
  254. // this.drawerConf.open(drawerType.node, node)
  255. // }
  256. // }
  257. // ]
  258. ],
  259. linkMenuList: [
  260. [
  261. {
  262. label: '删除',
  263. selected: (link, coordinate) => {
  264. link.remove()
  265. }
  266. }
  267. ]
  268. ],
  269. datas: {},
  270. dataRule: {
  271. mouldName: [{required: true, message: '请输入模板名称', trigger: 'blur'}]
  272. },
  273. dataRule1: {
  274. operatorIds: [{ required: true, message: '操作人员不能为空', trigger: 'change' }]
  275. }
  276. }
  277. },
  278. methods: {
  279. // 初始化表单
  280. async init (id, disable) {
  281. this.visible = true
  282. this.display = disable
  283. this.nodeList = []
  284. this.linkList = []
  285. this.mouldId = id;
  286. await getMonitoringDetail(id).then(async ({data}) => {
  287. if (data && data.code === '200') {
  288. this.dataForm = {...this.dataForm, proTechnologyStepList: data.data}
  289. console.log(this.dataForm.proTechnologyStepList)
  290. // 图纸
  291. if (this.dataForm.proTechnologyStepList) {
  292. const dataline = []
  293. const datanode = []
  294. await this.dataForm.proTechnologyStepList.forEach((v, i) => {
  295. // eslint-disable-next-line no-unused-vars
  296. const sortNo = []
  297. const datas = v.sort((a, b) => Number(a['sortNo']) - Number(b['sortNo']))
  298. let length = datas.length
  299. datas.forEach((item, index) => {
  300. const find = datanode.find(map => map.id === item.stepId)
  301. if (!find) {
  302. datanode.push({
  303. id: item.stepId,
  304. // width: (index === 0 || item.workTypeId === '0') ? 140 : 180,
  305. // height: (index === 0 || item.workTypeId === '0') ? 80 : 100,
  306. width: 140,
  307. height: 80,
  308. coordinate: item.coordinate.split(','),
  309. meta: {
  310. name: item.stepName + (item.state === '0' ? '(已完成)' : '(未完成)'),
  311. desc: item.operatorName,
  312. prop: index === 0 ? 'start' : (index === length - 1) ? 'end' : 'condition',
  313. notes: item.notes || '',
  314. workTypeId: item.workTypeId || '',
  315. type: item.type || '',
  316. operatorIds: item.operatorId == null ? [] : item.operatorId.split(',')
  317. }
  318. })
  319. }
  320. const id = item.stepId
  321. if ((index + 1) < datas.length) {
  322. if (datas[index + 1]) {
  323. dataline.push({
  324. id: uuid('link'),
  325. startId: id,
  326. endId: datas[index + 1].stepId,
  327. meta: '',
  328. // startAt: [(index === 0 || item.workTypeId === '0') ? 90 : 120, (index === 0 || item.workTypeId === '0') ? 25 : 35],
  329. // endAt: [0, (index === 0 || item.workTypeId === '0') ? 25 : 35]
  330. startAt: [120, 35],
  331. endAt: [0, 35]
  332. })
  333. }
  334. }
  335. })
  336. })
  337. this.$nextTick(() => {
  338. setTimeout(() => {
  339. this.nodeList = datanode
  340. this.linkList = dataline
  341. }, 200)
  342. })
  343. }
  344. }
  345. })
  346. },
  347. linkDesc (link) {
  348. return link.meta ? link.meta.desc : ''
  349. },
  350. settingSubmit () {
  351. this.$refs['nodeSetting'].validate((valid) => {
  352. if (valid) {
  353. const conf = this.drawerConf
  354. if (this.drawerConf.type === drawerType.node) {
  355. if (!conf.info.meta) conf.info.meta = {}
  356. Object.keys(this.nodeSetting).forEach(key => {
  357. if (key == 'operatorIds') {
  358. let idList = this.nodeSetting[key];
  359. let nameList = [];
  360. idList.forEach(id => {
  361. let name = this.operatorList.find(item => {
  362. return item.userId === id
  363. }).name
  364. nameList.push(name)
  365. })
  366. this.$set(conf.info.meta, 'desc', nameList.join(','))
  367. }
  368. this.$set(conf.info.meta, key, this.nodeSetting[key])
  369. })
  370. this.$refs.nodeSetting.resetFields()
  371. } else {
  372. if (!conf.info.meta) conf.info.meta = {}
  373. Object.keys(this.linkSetting).forEach(key => {
  374. this.$set(conf.info.meta, key, this.linkSetting[key])
  375. })
  376. this.$refs.linkSetting.resetFields()
  377. }
  378. conf.visible = false
  379. }
  380. })
  381. },
  382. dataFormSubmit () {},
  383. getLineData (dataAll, dList, lList, id, sortNo) {
  384. const _l = []
  385. lList.forEach(l => {
  386. if (l.start.id === id) {
  387. _l.push(l.end.id)
  388. }
  389. })
  390. if (!sortNo) {
  391. const data = dList.filter(v => v.meta.prop === 'start')[0]
  392. _l.forEach(item => {
  393. dataAll.push([{
  394. 'notes': data.meta.desc || '',
  395. 'sortNo': 0,
  396. 'stepId': data.id,
  397. 'stepName': data.meta.name,
  398. 'workTypeId': data.meta.workTypeId || null,
  399. 'type': data.meta.type || null,
  400. 'coordinate': data.coordinate.join(','),
  401. 'operatorIds': data.meta.operatorIds
  402. }])
  403. })
  404. }
  405. dList.forEach(v => {
  406. const _i = _l.indexOf(v.id)
  407. if (_i > -1) {
  408. if (!v.meta.workTypeId && v.meta.prop !== 'end') {
  409. this.$message.error('完善节点工种')
  410. return
  411. }
  412. if (!sortNo) {
  413. dataAll[_i].push({
  414. 'notes': v.meta.desc || '',
  415. 'sortNo': (sortNo + 1),
  416. 'stepId': v.id,
  417. 'stepName': v.meta.name,
  418. 'workTypeId': v.meta.workTypeId || null,
  419. 'type': v.meta.type || null,
  420. 'coordinate': v.coordinate.join(',')
  421. })
  422. this.getLineData(dataAll[_i], dList, lList, v.id, (sortNo + 1))
  423. } else {
  424. let _has = false
  425. dataAll.forEach(items => {
  426. if (items.stepId === v.id) {
  427. _has = true
  428. }
  429. })
  430. if (!_has) {
  431. dataAll.push({
  432. 'notes': v.meta.desc || '',
  433. 'sortNo': (sortNo + 1),
  434. 'stepId': v.id,
  435. 'stepName': v.meta.name,
  436. 'workTypeId': v.meta.prop === 'end' ? 0 : (v.meta.workTypeId || ''),
  437. 'type': v.meta.type || '',
  438. 'coordinate': v.coordinate.join(',')
  439. })
  440. }
  441. this.getLineData(dataAll, dList, lList, v.id, (sortNo + 1))
  442. }
  443. }
  444. })
  445. }
  446. }
  447. }
  448. </script>
  449. <style scoped lang='scss'>
  450. </style>