ctafts-add-or-detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <div>
  3. <div class="my-title">{{ isEdit ? '编辑' : '新增' }}</div>
  4. <el-form
  5. :model="dataForm"
  6. :rules="dataRule"
  7. ref="dataForm"
  8. label-width="auto"
  9. >
  10. <el-row class="my-row">
  11. <el-col :span="8">
  12. <el-form-item label="工艺名称" prop="techName">
  13. <el-input
  14. v-model="dataForm.techName"
  15. :disabled="display || isEdit"
  16. placeholder="工艺名称"
  17. ></el-input>
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="8">
  21. <el-form-item label="工艺版本" prop="techVersion">
  22. <el-input
  23. v-model="dataForm.techVersion"
  24. :disabled="display || isEdit"
  25. placeholder="工艺版本"
  26. ></el-input>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="8">
  30. <el-form-item label="物料" prop="productId">
  31. <el-select
  32. v-model="dataForm.productId"
  33. :disabled="display || isEdit"
  34. remote
  35. filterable
  36. placeholder="请选择"
  37. style="width:100%"
  38. @change="productIdChangeHandle"
  39. >
  40. <el-option
  41. v-for="item in optionLevel"
  42. :key="item.productId"
  43. :label="item.productNameStr"
  44. :value="item.productId"
  45. >
  46. </el-option>
  47. </el-select>
  48. </el-form-item>
  49. </el-col>
  50. </el-row>
  51. <el-form-item label="备注说明">
  52. <el-input
  53. v-model="dataForm.notes"
  54. :disabled="display || isEdit"
  55. placeholder="备注说明"
  56. ></el-input>
  57. </el-form-item>
  58. <el-form-item label="" label-width="0px">
  59. <upload-component
  60. :display="display"
  61. :display-star="false"
  62. :title="'附件'"
  63. :accept="'*'"
  64. :file-obj-list="fileList"
  65. @uploadSuccess="uploadSuccess"
  66. />
  67. </el-form-item>
  68. <el-form-item label="工艺步骤" prop="nodeList"> </el-form-item>
  69. <el-row
  70. class="my-row"
  71. style="height: 350px; background-color: #efefef;"
  72. >
  73. <work-flow
  74. ref="workFlow"
  75. :nodeData="workFlowData"
  76. @saveWorkFlow="saveWorkFlow"
  77. :isEdit="isEdit"
  78. @dataChange="workFlowDataChange"
  79. ></work-flow>
  80. </el-row>
  81. <div style="margin-top:10px; border:1px solid #ccc; padding:5px">
  82. <div>
  83. <el-button @click="refreshTable">表格刷新</el-button>
  84. </div>
  85. <el-table :data="workFlowTableData">
  86. <el-table-column prop="nodeName" label="节点名称"></el-table-column>
  87. <el-table-column prop="workTypeName" label="工种类型"></el-table-column>
  88. <el-table-column prop="require" label="工序要求"></el-table-column>
  89. <el-table-column prop="explain" label="工序说明"></el-table-column>
  90. <el-table-column prop="process" label="工序特性"></el-table-column>
  91. <el-table-column prop="notes" label="备注"></el-table-column>
  92. </el-table>
  93. </div>
  94. </el-form>
  95. <span slot="footer" class="dialog-footer">
  96. <el-button @click="onChose">取消</el-button>
  97. <el-button v-if="!display" type="primary" @click="dataFormSubmit()"
  98. >确定</el-button
  99. >
  100. </span>
  101. <!-- </el-dialog> -->
  102. </div>
  103. </template>
  104. <script>
  105. import { getInfo, getProduct, getWorkType } from '@/api/crafts'
  106. import UploadComponent from '../common/upload-component'
  107. import WorkFlow from '@/components/work-flow/home'
  108. // import data from "@/components/work-flow/config/data.json";
  109. import { GenNonDuplicateID } from '@/components/work-flow/until'
  110. export default {
  111. name: 'add-or-update',
  112. components: { UploadComponent, WorkFlow },
  113. computed: {
  114. orgId: {
  115. get () {
  116. return this.$store.state.user.orgId
  117. }
  118. }
  119. },
  120. data () {
  121. return {
  122. datas: {},
  123. visible: false,
  124. display: false,
  125. isEdit: false, // 是否是编辑页面
  126. isCopy: false,
  127. fileList: [],
  128. dataList: [],
  129. id: 0,
  130. dataForm: {
  131. techName: '',
  132. techVersion: '',
  133. productId: '',
  134. notes: ''
  135. },
  136. previewPath: '',
  137. previewName: '',
  138. previewVisible: false,
  139. optionsProducts: [],
  140. optionLevel: [],
  141. workFlowData: {
  142. nodeList: [],
  143. lineList: []
  144. }, // 流程图数据
  145. // 工艺流程表格数据
  146. workFlowTableData: [],
  147. // 工种列表
  148. workTypeOptions: [],
  149. dataRule: {
  150. techName: [
  151. { required: true, message: '工艺名称不能为空', trigger: 'blur' }
  152. ],
  153. techVersion: [
  154. { required: true, message: '工艺版本不能为空', trigger: 'blur' }
  155. ],
  156. productId: [
  157. { required: true, message: '物料不能为空', trigger: 'change' }
  158. ]
  159. },
  160. dataRule1: {
  161. name: [
  162. { required: true, message: '节点名称不能为空', trigger: 'blur' }
  163. ],
  164. type: [
  165. { required: true, message: '节点类型不能为空', trigger: 'change' }
  166. ],
  167. workTypeId: [
  168. { required: true, message: '工种不能为空', trigger: 'change' }
  169. ]
  170. }
  171. }
  172. },
  173. created () {
  174. this.initNode()
  175. },
  176. mounted () {
  177. this.initNode()
  178. },
  179. methods: {
  180. onChose () {
  181. this.$emit('onChose')
  182. },
  183. initNode () {
  184. // this.workFlowData = data;
  185. },
  186. resetWorkFlow () {
  187. this.workFlowData = {
  188. nodeList: [],
  189. lineList: []
  190. }
  191. },
  192. async init (id, display, isEdit, isCopy) {
  193. this.fileList = []
  194. this.dataForm = {
  195. techName: '',
  196. techVersion: '',
  197. productId: '',
  198. notes: ''
  199. }
  200. this.visible = true
  201. this.display = display
  202. this.isEdit = isEdit && !isCopy
  203. this.isCopy = isCopy
  204. await getProduct({ current: 1, size: 20000 }).then(({ data }) => {
  205. if (data && data.code === '200') {
  206. this.optionLevel = data.data.records
  207. this.optionLevel.forEach(item => {
  208. item.productNameStr = item.productName + '-' + item.mapNumber + '-' + (item.techId && item.techId !== 0 ? '有' : '无')
  209. })
  210. }
  211. })
  212. if (!id) return
  213. await getInfo(id).then(async ({ data }) => {
  214. if (data && data.code === '200') {
  215. this.dataForm = data.data
  216. // 附件
  217. if (data.data.attachList) {
  218. data.data.attachList.forEach(item => {
  219. this.fileList.push({
  220. name: item.fileName,
  221. url: item.url,
  222. id: item.url
  223. })
  224. })
  225. }
  226. // 工艺流程
  227. this.workFlowData = {
  228. nodeList: data.data.nodeList,
  229. lineList: data.data.lineList
  230. }
  231. }
  232. })
  233. this.refreshTable()
  234. },
  235. productIdChangeHandle (val) {
  236. if (val) {
  237. let item = this.optionLevel.find(t => t.productId === val)
  238. this.dataForm.techName = item.productName
  239. }
  240. console.log(111, val)
  241. },
  242. handleRemove (file, fileList) {
  243. this.fileList = fileList
  244. },
  245. handleChange (file, fileList) {
  246. this.fileList = fileList
  247. },
  248. handleExceed (files, fileList) {
  249. this.$message.warning(
  250. `当前限制选择 5 个文件,本次选择了 ${
  251. files.length
  252. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  253. )
  254. },
  255. validateField (type) {
  256. this.$refs.dataForm.validateField(type)
  257. },
  258. // 表单提交
  259. dataFormSubmit () {
  260. let flowData = this.$refs.workFlow.getFlowData()
  261. if (!flowData) {
  262. this.$message.error('请先完成流程图!')
  263. return
  264. }
  265. this.$refs['dataForm'].validate(valid => {
  266. if (valid) {
  267. // 填充附件
  268. let fList = this.fileList
  269. if (fList.length > 0) {
  270. this.dataForm.attachList = []
  271. for (let i = 0; i < fList.length; i++) {
  272. this.dataForm.attachList.push({
  273. fileName: fList[i].name,
  274. url: fList[i].url
  275. })
  276. }
  277. }
  278. let url = `/biz-service/technology/submit`
  279. if (this.isEdit && !this.isCopy) {
  280. url = `/biz-service/technology/update`
  281. }
  282. if (this.isCopy) {
  283. this.dataForm.id = 0
  284. this.dataForm.techId = null
  285. if (flowData.nodeList != null && flowData.nodeList.length > 0) {
  286. for (let index = 0; index < flowData.nodeList.length; index++) {
  287. let oldId = flowData.nodeList[index].id
  288. let newId = GenNonDuplicateID(8)
  289. flowData.nodeList[index].techId = null
  290. flowData.nodeList[index].id = newId
  291. if (flowData.lineList != null && flowData.lineList.length > 0) {
  292. for (let index = 0; index < flowData.lineList.length; index++) {
  293. flowData.lineList[index].techId = null
  294. flowData.lineList[index].id = GenNonDuplicateID(8)
  295. let from = flowData.lineList[index].from
  296. let to = flowData.lineList[index].to
  297. if (from === oldId) {
  298. flowData.lineList[index].from = newId
  299. }
  300. if (to === oldId) {
  301. flowData.lineList[index].to = newId
  302. }
  303. }
  304. }
  305. }
  306. }
  307. }
  308. this.$http({
  309. url: this.$http.adornUrl(url),
  310. method: 'post',
  311. data: this.$http.adornData({
  312. ...this.dataForm,
  313. ...flowData
  314. })
  315. }).then(({ data }) => {
  316. if (data && data.code === '200') {
  317. this.$message({
  318. message: '操作成功',
  319. type: 'success',
  320. duration: 1500,
  321. onClose: () => {
  322. this.resetWorkFlow()
  323. this.onChose()
  324. this.$emit('refreshDataList')
  325. }
  326. })
  327. } else {
  328. this.$message.error(data.msg)
  329. }
  330. })
  331. }
  332. })
  333. },
  334. uploadSuccess (fileList) {
  335. this.fileList = fileList
  336. },
  337. // 保存流程图
  338. saveWorkFlow (workFlowData) {
  339. console.log('save work flow.')
  340. this.workFlowData = workFlowData
  341. },
  342. handleClose () {
  343. // this.visible = false
  344. this.$emit('close')
  345. },
  346. // 流程图数据变更通知
  347. workFlowDataChange () {
  348. this.refreshTable()
  349. },
  350. // 刷新表格
  351. async refreshTable () {
  352. this.workFlowTableData = []
  353. await this.getWorkTypeOptions()
  354. let flowData = this.$refs.workFlow.getFlowData()
  355. flowData.nodeList.forEach(item => {
  356. let workType = this.workTypeOptions.find(t => t.typeId === item.workTypeId)
  357. if (workType) {
  358. item.workTypeName = workType.name
  359. }
  360. this.workFlowTableData.push(item)
  361. })
  362. },
  363. async getWorkTypeOptions () {
  364. this.workTypeOptions = []
  365. await getWorkType().then(({ data }) => {
  366. if (data && data.code === '200') {
  367. this.workTypeOptions = data.data
  368. console.log(data.data)
  369. }
  370. })
  371. }
  372. }
  373. }
  374. </script>
  375. <style lang="less" scoped>
  376. .super-flow__node {
  377. .flow-node {
  378. > header {
  379. font-size: 14px;
  380. height: 32px;
  381. line-height: 32px;
  382. padding: 0 12px;
  383. color: #ffffff;
  384. }
  385. > section {
  386. text-align: center;
  387. line-height: 20px;
  388. overflow: hidden;
  389. padding: 6px 12px;
  390. word-break: break-all;
  391. }
  392. &.flow-node-start {
  393. > header {
  394. background-color: #55abfc;
  395. }
  396. }
  397. &.flow-node-condition {
  398. > header {
  399. background-color: #bc1d16;
  400. }
  401. }
  402. &.flow-node-approval {
  403. > header {
  404. background-color: rgba(188, 181, 58, 0.76);
  405. }
  406. }
  407. &.flow-node-cc {
  408. > header {
  409. background-color: #30b95c;
  410. }
  411. }
  412. &.flow-node-end {
  413. > header {
  414. height: 50px;
  415. line-height: 50px;
  416. background-color: rgb(0, 0, 0);
  417. }
  418. }
  419. }
  420. }
  421. </style>