scheduling-mould-details.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div class="production">
  3. <!-- <el-dialog
  4. :title="dialogTitle"
  5. width="70%"
  6. :close-on-click-modal="false"
  7. :visible.sync="visible"
  8. @close="handleClose"
  9. > -->
  10. <div class="my-title">{{ dialogTitle }}</div>
  11. <el-form
  12. :model="dataForm"
  13. :rules="dataRule"
  14. ref="dataForm"
  15. label-width="auto"
  16. >
  17. <el-row class="my-row" :gutter="20">
  18. <el-col :span="8">
  19. <el-form-item label="物料" prop="productId">
  20. <el-input v-if="disable && productName" :disabled="disable" v-model="productName"></el-input>
  21. <el-select
  22. v-else
  23. v-model="dataForm.productId"
  24. @change="productChange"
  25. remote
  26. :disabled="disable"
  27. placeholder="请选择"
  28. style="width:100%"
  29. >
  30. <el-option
  31. v-for="item in productList"
  32. :key="item.productId"
  33. :label="item.productName"
  34. :value="item.productId"
  35. >
  36. </el-option>
  37. </el-select>
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="10">
  41. <el-form-item label="模板名称" prop="mouldName">
  42. <el-input
  43. placeholder="请输入模板名称"
  44. v-model="dataForm.mouldName"
  45. maxlength="30"
  46. show-word-limit
  47. ></el-input>
  48. </el-form-item>
  49. </el-col>
  50. </el-row>
  51. <el-row
  52. class="my-row"
  53. style="height: 350px; background-color: #efefef;"
  54. >
  55. <work-flow
  56. ref="workFlow"
  57. :nodeData="workFlowData"
  58. :selectOperator="true"
  59. :isEdit="true"
  60. ></work-flow>
  61. </el-row>
  62. </el-form>
  63. <span slot="footer" class="dialog-footer">
  64. <el-button @click="onChose">取消</el-button>
  65. <el-button type="primary" @click="dataFormSubmit()">确认提交</el-button>
  66. </span>
  67. <!-- </el-dialog> -->
  68. </div>
  69. </template>
  70. <script>
  71. import {
  72. getMouldDetail,
  73. getProductList,
  74. getMouldDetailByProductId,
  75. saveProdProductionMould,
  76. updateProdProductionMould
  77. } from '@/api/production'
  78. import { workTypeMasterList } from '@/api/worktype'
  79. import WorkFlow from '@/components/work-flow/home'
  80. export default {
  81. name: 'scheduling-details',
  82. components: {
  83. WorkFlow
  84. },
  85. data () {
  86. return {
  87. mouldId: '',
  88. visible: false,
  89. dialogTitle: '',
  90. dataForm: {
  91. mouldName: ''
  92. },
  93. operatorList: [],
  94. operatorIds: [],
  95. productList: [],
  96. disable: false,
  97. productName: '',
  98. datas: {},
  99. workFlowData: {
  100. nodeList: [],
  101. lineList: []
  102. },
  103. dataRule: {
  104. mouldName: [
  105. { required: true, message: '请输入模板名称', trigger: 'blur' }
  106. ]
  107. },
  108. dataRule1: {
  109. operatorIds: [
  110. { required: true, message: '操作人员不能为空', trigger: 'change' }
  111. ]
  112. }
  113. }
  114. },
  115. methods: {
  116. onChose () {
  117. this.$emit('onChose')
  118. },
  119. // 初始化物料名称列表
  120. async initProductList () {
  121. getProductList().then(({ data }) => {
  122. if (data && data.code === '200') {
  123. data.data.forEach(item => {
  124. this.productList.push(item)
  125. })
  126. }
  127. })
  128. },
  129. // 初始化表单
  130. async init (id, disable, productName) {
  131. this.disable = disable
  132. this.dialogTitle = disable ? '编辑排产模板' : '新增排产模板'
  133. this.mouldId = id
  134. this.productName = productName
  135. this.visible = true
  136. if (!disable) {
  137. await this.initProductList()
  138. }
  139. if (id > 0) {
  140. await getMouldDetail(id).then(async ({ data }) => {
  141. if (data && data.code === '200') {
  142. this.dataForm = data.data
  143. // 流程图展示
  144. this.workFlowData = {
  145. nodeList: data.data.nodeList,
  146. lineList: data.data.lineList
  147. }
  148. }
  149. })
  150. }
  151. // if (productionId && productionId > 0) {
  152. // this.productChange(productionId)
  153. // }
  154. },
  155. // 根据物料ID查询步骤详情
  156. async productChange (productId) {
  157. this.$confirm('选中后不可更改,是否选择该物料?', '提示', {
  158. confirmButtonText: '确定',
  159. cancelButtonText: '取消',
  160. type: 'warning'
  161. }).then(() => {
  162. this.disable = true
  163. getMouldDetailByProductId(productId).then(async ({ data }) => {
  164. if (data && data.code === '200') {
  165. this.dataForm = {
  166. ...this.dataForm
  167. }
  168. // 流程图展示
  169. this.workFlowData = {
  170. nodeList: data.data.nodeList,
  171. lineList: data.data.lineList
  172. }
  173. } else {
  174. this.$message({
  175. type: 'error',
  176. message: data.msg
  177. })
  178. }
  179. })
  180. }).catch(() => {
  181. this.dataForm.productId = ''
  182. })
  183. },
  184. // 按工种ID查询操作人列表
  185. getOperatorList (workTypeId) {
  186. workTypeMasterList(workTypeId).then(({ data }) => {
  187. if (data && data.code === '200') {
  188. this.operatorList = []
  189. data.data.forEach(item => {
  190. this.operatorList.push(item)
  191. })
  192. }
  193. })
  194. },
  195. dataFormSubmit () {
  196. let flowData = this.$refs.workFlow.getFlowData()
  197. if (!flowData) {
  198. this.$message.error('请先完成流程图!')
  199. return
  200. }
  201. this.$refs['dataForm'].validate(valid => {
  202. if (valid) {
  203. // eslint-disable-next-line no-unused-vars
  204. let productionPlanNodes = []
  205. for (
  206. let index = 0;
  207. index < flowData.nodeList.length;
  208. index++
  209. ) {
  210. const node = flowData.nodeList[index]
  211. if (node.type !== 'end' && node.operatorId === '') {
  212. this.$message.error(`请选择 ${node.nodeName} 的操作人员!`)
  213. this.clickFlowSave = false
  214. return
  215. }
  216. productionPlanNodes.push({
  217. techNodeId: node.id,
  218. operatorId: node.operatorId,
  219. planCompletionTime: node.planCompletionTime
  220. })
  221. }
  222. let submitData = {
  223. mouldName: this.dataForm.mouldName,
  224. productId: this.dataForm.productId,
  225. nodeList: productionPlanNodes
  226. }
  227. if (this.mouldId === 0) {
  228. // 新增
  229. saveProdProductionMould(submitData)
  230. .then(({ data }) => {
  231. if (data && data.code === '200') {
  232. this.$message({
  233. message: '操作成功',
  234. type: 'success',
  235. duration: 1500,
  236. onClose: () => {
  237. this.onChose()
  238. this.$emit('refreshDataList')
  239. }
  240. })
  241. } else {
  242. this.$message.error(data.msg)
  243. }
  244. })
  245. .catch(() => {
  246. })
  247. } else {
  248. // 更新
  249. submitData.mouldId = this.mouldId
  250. updateProdProductionMould(submitData)
  251. .then(({ data }) => {
  252. if (data && data.code === '200') {
  253. this.$message({
  254. message: '操作成功',
  255. type: 'success',
  256. duration: 1500,
  257. onClose: () => {
  258. this.onChose()
  259. this.$emit('refreshDataList')
  260. }
  261. })
  262. } else {
  263. this.$message.error(data.msg)
  264. }
  265. })
  266. .catch(() => {
  267. })
  268. }
  269. }
  270. })
  271. },
  272. handleClose () {
  273. this.$emit('close')
  274. }
  275. }
  276. }
  277. </script>
  278. <style scoped></style>