ctafts-add-or-detail.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="display ? '工艺详情' : '新建工艺'"
  5. width="70%"
  6. :close-on-click-modal="false"
  7. :visible.sync="visible"
  8. >
  9. <el-form
  10. :model="dataForm"
  11. :rules="dataRule"
  12. ref="dataForm"
  13. label-width="auto"
  14. >
  15. <el-row class="my-row">
  16. <el-col :span="8">
  17. <el-form-item label="工艺名称" prop="techName">
  18. <el-input
  19. v-model="dataForm.techName"
  20. :disabled="display"
  21. placeholder="工艺名称"
  22. ></el-input>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="8">
  26. <el-form-item label="工艺版本" prop="techVersion">
  27. <el-input
  28. v-model="dataForm.techVersion"
  29. :disabled="display"
  30. placeholder="工艺版本"
  31. ></el-input>
  32. </el-form-item>
  33. </el-col>
  34. <el-col :span="8">
  35. <el-form-item label="产品" prop="productId">
  36. <el-select
  37. v-model="dataForm.productId"
  38. :disabled="display"
  39. remote
  40. placeholder="请选择"
  41. >
  42. <el-option
  43. v-for="item in optionLevel"
  44. :key="item.productId"
  45. :label="item.productName"
  46. :value="item.productId"
  47. >
  48. </el-option>
  49. </el-select>
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. <el-form-item label="备注说明">
  54. <el-input
  55. v-model="dataForm.notes"
  56. :disabled="display"
  57. placeholder="备注说明"
  58. ></el-input>
  59. </el-form-item>
  60. <el-form-item label="" label-width="0px">
  61. <upload-component
  62. :display="display"
  63. :title="'附件'"
  64. :accept="'*'"
  65. :file-obj-list="fileList"
  66. @uploadSuccess="uploadSuccess"
  67. />
  68. </el-form-item>
  69. <el-form-item label="工艺步骤" prop="nodeList"> </el-form-item>
  70. <el-row
  71. class="my-row"
  72. style="height: 350px; background-color: #efefef;"
  73. >
  74. <work-flow
  75. ref="workFlow"
  76. :nodeData="workFlowData"
  77. @saveWorkFlow="saveWorkFlow"
  78. ></work-flow>
  79. </el-row>
  80. </el-form>
  81. <span slot="footer" class="dialog-footer">
  82. <el-button @click="visible = false">取消</el-button>
  83. <el-button v-if="!display" type="primary" @click="dataFormSubmit()"
  84. >确定</el-button
  85. >
  86. </span>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script>
  91. import { getInfo, getProduct, getWorkType } from '@/api/crafts'
  92. import UploadComponent from '../common/upload-component'
  93. import WorkFlow from '@/components/work-flow/home'
  94. // import data from "@/components/work-flow/config/data.json";
  95. export default {
  96. name: 'add-or-update',
  97. components: { UploadComponent, WorkFlow },
  98. computed: {
  99. orgId: {
  100. get () {
  101. return this.$store.state.user.orgId
  102. }
  103. }
  104. },
  105. data () {
  106. return {
  107. workTypeOptions: [],
  108. datas: {},
  109. visible: false,
  110. display: false,
  111. fileList: [],
  112. dataList: [],
  113. id: 0,
  114. dataForm: {
  115. techName: '',
  116. techVersion: '',
  117. productId: '',
  118. notes: ''
  119. },
  120. previewPath: '',
  121. previewName: '',
  122. previewVisible: false,
  123. optionsProducts: [],
  124. optionLevel: [],
  125. workFlowData: {
  126. nodeList: [],
  127. lineList: []
  128. }, // 流程图数据
  129. dataRule: {
  130. techName: [
  131. { required: true, message: '工艺名称不能为空', trigger: 'blur' }
  132. ],
  133. techVersion: [
  134. { required: true, message: '工艺版本不能为空', trigger: 'blur' }
  135. ],
  136. productId: [
  137. { required: true, message: '产品不能为空', trigger: 'change' }
  138. ]
  139. },
  140. dataRule1: {
  141. name: [
  142. { required: true, message: '节点名称不能为空', trigger: 'blur' }
  143. ],
  144. type: [
  145. { required: true, message: '节点类型不能为空', trigger: 'change' }
  146. ],
  147. workTypeId: [
  148. { required: true, message: '工种不能为空', trigger: 'change' }
  149. ]
  150. }
  151. }
  152. },
  153. created () {
  154. this.initNode()
  155. },
  156. mounted () {
  157. this.initNode()
  158. },
  159. methods: {
  160. initNode () {
  161. // this.workFlowData = data;
  162. },
  163. resetWorkFlow () {
  164. this.workFlowData = {
  165. nodeList: [],
  166. lineList: []
  167. }
  168. },
  169. async init (id, display) {
  170. this.dataForm = {
  171. techName: '',
  172. techVersion: '',
  173. productId: '',
  174. notes: ''
  175. }
  176. this.visible = true
  177. this.display = display
  178. await getProduct({ current: 1, size: 20000 }).then(({ data }) => {
  179. if (data && data.code === '200') {
  180. this.optionLevel = data.data.records
  181. }
  182. })
  183. if (!id) return
  184. await getInfo(id).then(async ({ data }) => {
  185. if (data && data.code === '200') {
  186. this.dataForm = data.data
  187. }
  188. })
  189. },
  190. getWorkType () {
  191. getWorkType().then(({ data }) => {
  192. if (data && data.code === '200') {
  193. this.workTypeOptions = data.data
  194. }
  195. })
  196. },
  197. handleRemove (file, fileList) {
  198. this.fileList = fileList
  199. },
  200. handleChange (file, fileList) {
  201. this.fileList = fileList
  202. },
  203. handleExceed (files, fileList) {
  204. this.$message.warning(
  205. `当前限制选择 5 个文件,本次选择了 ${
  206. files.length
  207. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  208. )
  209. },
  210. validateField (type) {
  211. this.$refs.dataForm.validateField(type)
  212. },
  213. // 表单提交
  214. dataFormSubmit () {
  215. if (!this.workFlowData) {
  216. this.$message.error('请先完成流程图!')
  217. return
  218. }
  219. this.$refs['dataForm'].validate(valid => {
  220. if (valid) {
  221. // 填充附件
  222. let fList = this.fileList
  223. if (fList.length > 0) {
  224. this.dataForm.attachList = []
  225. for (let i = 0; i < fList.length; i++) {
  226. this.dataForm.attachList.push({
  227. fileName: fList[i].name,
  228. url: fList[i].url
  229. })
  230. }
  231. }
  232. this.$http({
  233. url: this.$http.adornUrl(`/biz-service/technology/submit`),
  234. method: 'post',
  235. data: this.$http.adornData({
  236. ...this.dataForm,
  237. ...this.workFlowData
  238. })
  239. }).then(({ data }) => {
  240. if (data && data.code === '200') {
  241. this.$message({
  242. message: '操作成功',
  243. type: 'success',
  244. duration: 1500,
  245. onClose: () => {
  246. this.resetWorkFlow()
  247. this.$emit('refreshDataList')
  248. this.visible = false
  249. }
  250. })
  251. } else {
  252. this.$message.error(data.msg)
  253. }
  254. })
  255. }
  256. })
  257. },
  258. uploadSuccess (fileList) {
  259. this.fileList = fileList
  260. },
  261. // 保存流程图
  262. saveWorkFlow (workFlowData) {
  263. this.workFlowData = workFlowData
  264. }
  265. }
  266. }
  267. </script>
  268. <style lang="less" scoped>
  269. .super-flow__node {
  270. .flow-node {
  271. > header {
  272. font-size: 14px;
  273. height: 32px;
  274. line-height: 32px;
  275. padding: 0 12px;
  276. color: #ffffff;
  277. }
  278. > section {
  279. text-align: center;
  280. line-height: 20px;
  281. overflow: hidden;
  282. padding: 6px 12px;
  283. word-break: break-all;
  284. }
  285. &.flow-node-start {
  286. > header {
  287. background-color: #55abfc;
  288. }
  289. }
  290. &.flow-node-condition {
  291. > header {
  292. background-color: #bc1d16;
  293. }
  294. }
  295. &.flow-node-approval {
  296. > header {
  297. background-color: rgba(188, 181, 58, 0.76);
  298. }
  299. }
  300. &.flow-node-cc {
  301. > header {
  302. background-color: #30b95c;
  303. }
  304. }
  305. &.flow-node-end {
  306. > header {
  307. height: 50px;
  308. line-height: 50px;
  309. background-color: rgb(0, 0, 0);
  310. }
  311. }
  312. }
  313. }
  314. </style>