product-add-or-update.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <div>
  3. <!-- <el-dialog
  4. :title="!id ? '新增': display ? '详情' : '修改'"
  5. width="70%"
  6. :close-on-click-modal="false"
  7. :visible.sync="visible"> -->
  8. <div class="my-title">{{ !id ? '新增' : display ? '详情' : '修改' }}</div>
  9. <!-- 工作流 -->
  10. <div v-show="display && dataForm.workFlowBusinessExt">
  11. <el-steps
  12. :active="dataForm.workFlowBusinessExt && dataForm.workFlowBusinessExt.workFlowProcessStepList ? dataForm.workFlowBusinessExt.workFlowProcessStepList.length + 2 : 0"
  13. align-center style="margin-bottom: 20px">
  14. <template v-for="(item, i) in stepList">
  15. <el-step :icon="item.icon" :title="item.title" :description="item.description"></el-step>
  16. </template>
  17. </el-steps>
  18. <el-collapse style="margin-bottom: 20px">
  19. <el-collapse-item>
  20. <template slot="title">
  21. <span style="color: red">审批日志(展开查看更多):</span>
  22. </template>
  23. <template v-for="(item, i) in logList">
  24. <div>{{+ + i }}:{{ item.approverName }} {{ item.createTime }} {{ item.approvalValue }}</div>
  25. </template>
  26. </el-collapse-item>
  27. </el-collapse>
  28. </div>
  29. <!-- 表单 -->
  30. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
  31. <el-row class="my-row">
  32. <el-col :span="8">
  33. <el-form-item label="物料名称" prop="productName">
  34. <el-input v-model="dataForm.productName" :disabled="display" placeholder="物料名称"></el-input>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="8">
  38. <el-form-item label="物料规格" prop="productSpec">
  39. <el-input v-model="dataForm.productSpec" :disabled="display" placeholder="物料规格"></el-input>
  40. </el-form-item>
  41. </el-col>
  42. <el-col :span="8">
  43. <el-form-item label="物料类别" prop="productType">
  44. <el-select v-model="dataForm.productType" :disabled="display" remote placeholder="请选择">
  45. <el-option v-for="item in optionsType" :key="item.code" :label="item.value" :value="item.code">
  46. </el-option>
  47. </el-select>
  48. </el-form-item>
  49. </el-col>
  50. </el-row>
  51. <el-row class="my-row">
  52. <el-col :span="8">
  53. <el-form-item label="材料" prop="materials">
  54. <el-input v-model="dataForm.materials" :disabled="display" placeholder="材料"></el-input>
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="8">
  58. <el-form-item label="物料尺寸" prop="size">
  59. <el-input v-model="dataForm.size" :disabled="display" placeholder="物料尺寸"></el-input>
  60. </el-form-item>
  61. </el-col>
  62. <el-col :span="8">
  63. <el-form-item label="展开尺寸" prop="developedSize">
  64. <el-input v-model="dataForm.developedSize" :disabled="display" placeholder="展开尺寸"></el-input>
  65. </el-form-item>
  66. </el-col>
  67. </el-row>
  68. <el-row class="my-row">
  69. <el-col :span="8">
  70. <el-form-item label="单位" prop="unit">
  71. <el-input v-model="dataForm.unit" :disabled="display" placeholder="单位"></el-input>
  72. </el-form-item>
  73. </el-col>
  74. <el-col :span="8">
  75. <el-form-item label="单套数量" prop="cnt">
  76. <el-input v-model="dataForm.cnt" :disabled="display" placeholder="单套数量"></el-input>
  77. </el-form-item>
  78. </el-col>
  79. <el-col :span="8">
  80. <el-form-item label="主图号" prop="mapNumber">
  81. <el-input v-model="dataForm.mapNumber" :disabled="display" placeholder="主图号"></el-input>
  82. </el-form-item>
  83. </el-col>
  84. </el-row>
  85. <el-row>
  86. <el-col>
  87. <el-form-item label="表面处理" prop="surfaceTreatment">
  88. <el-input v-model="dataForm.surfaceTreatment" :disabled="display" placeholder="" type="textarea"></el-input>
  89. </el-form-item>
  90. </el-col>
  91. </el-row>
  92. <el-row>
  93. <el-col>
  94. <el-form-item label="热处理" prop="heatTreatment">
  95. <el-input v-model="dataForm.heatTreatment" :disabled="display" placeholder="" type="textarea"></el-input>
  96. </el-form-item>
  97. </el-col>
  98. </el-row>
  99. <el-row>
  100. <el-col>
  101. <el-form-item label="备注" prop="notes">
  102. <el-input v-model="dataForm.notes" :disabled="display" placeholder="" type="textarea"></el-input>
  103. </el-form-item>
  104. </el-col>
  105. </el-row>
  106. <el-row>
  107. <el-col>
  108. <el-form-item label="关重件" prop="importance">
  109. <el-input v-model="dataForm.importance" :disabled="display" placeholder="" type="textarea"></el-input>
  110. </el-form-item>
  111. </el-col>
  112. </el-row>
  113. <el-row class="my-row">
  114. <el-col :span="8">
  115. <el-form-item label="简图" prop="attachList2">
  116. <upload-component :accept="'.jpg,.jpeg,.png'" v-model="dataForm.attachList2" />
  117. </el-form-item>
  118. </el-col>
  119. <el-col :span="8" :offset="4">
  120. <el-form-item label="技术资料附件" prop="attachList">
  121. <upload-component :accept="'*'" v-model="dataForm.attachList" />
  122. </el-form-item>
  123. </el-col>
  124. </el-row>
  125. <el-row>
  126. <div class="title"> 关联图纸</div>
  127. <el-table :data="drawingList" border style="width: 100%;">
  128. <el-table-column label="序号" type="index" width="50" align="center">
  129. </el-table-column>
  130. <el-table-column prop="drawingName" header-align="center" align="center" label="图纸名称">
  131. </el-table-column>
  132. <el-table-column prop="drawingNo" header-align="center" align="center" label="图号">
  133. </el-table-column>
  134. <el-table-column prop="source" header-align="center" align="center" label="来源">
  135. </el-table-column>
  136. <el-table-column prop="notes" header-align="center" align="center" label="备注">
  137. </el-table-column>
  138. <el-table-column fixed="right"
  139. header-align="center"
  140. align="center"
  141. width="80"
  142. label="操作">
  143. <template slot-scope="scope">
  144. <el-button style="color: red" type="text" size="small" @click="removeDrawingItem(scope.$index)">移除</el-button>
  145. </template>
  146. </el-table-column>
  147. </el-table>
  148. <el-row style="text-align: center; margin-top: 10px;">
  149. <el-button v-show="!display" type="primary" icon="el-icon-plus" @click="addDrawingList"></el-button>
  150. </el-row>
  151. </el-row>
  152. <el-row class="my-row">
  153. <el-form-item label="是否组合物料" prop="displayProductList">
  154. <el-switch v-model="displayProductList" active-color="#13ce66" inactive-color="#ff4949" active-text="是"
  155. inactive-text="否">
  156. </el-switch>
  157. </el-form-item>
  158. </el-row>
  159. <el-row v-if="displayProductList">
  160. <div class="title"><span style="color: red">*</span> 组合小物料</div>
  161. <el-table :data="productDetails" border style="width: 100%;">
  162. <el-table-column label="序号" type="index" width="50" align="center">
  163. </el-table-column>
  164. <el-table-column prop="productName" header-align="center" align="center" label="物料名称">
  165. </el-table-column>
  166. <el-table-column prop="productSpec" header-align="center" align="center" label="规格">
  167. </el-table-column>
  168. <el-table-column prop="cnt" header-align="center" align="center" label="数量" width="170">
  169. <template slot-scope="scope">
  170. <el-input-number v-model="scope.row.cnt" :disabled="display" :min="1" style="width: 140px;" />
  171. </template>
  172. </el-table-column>
  173. <el-table-column prop="notes" header-align="center" align="center" label="备注">
  174. </el-table-column>
  175. <el-table-column
  176. fixed="right"
  177. header-align="center"
  178. align="center"
  179. width="80"
  180. label="操作">
  181. <template slot-scope="scope">
  182. <el-button style="color: red" type="text" size="small" @click="deleteProductHandle(scope.row.proProductId)">移除</el-button>
  183. </template>
  184. </el-table-column>
  185. </el-table>
  186. <el-row style="text-align: center; margin-top: 10px;">
  187. <el-button v-show="!display" type="primary" icon="el-icon-plus" @click="addProduct"></el-button>
  188. </el-row>
  189. </el-row>
  190. </el-form>
  191. <span slot="footer" class="dialog-footer">
  192. <el-button @click="onChose">取消</el-button>
  193. <el-button v-if="!display" type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
  194. </span>
  195. <!-- </el-dialog> -->
  196. <template-chose v-if="productListVisible" ref="productList" @addItems="addProductItems" />
  197. <templateChoseMaterial v-if="materialListVisible" ref="materialList" @addItems="addMaterialItems" />
  198. <template-draw-choose v-if="drawListVisible" ref="drawList" @addItems="addDrawItems" />
  199. </div>
  200. </template>
  201. <script>
  202. import templateChose from '../product/template-chose'
  203. import templateChoseMaterial from '../product/template-chose-material'
  204. import templateDrawChoose from './draw-template-choose'
  205. import { getDictList } from '@/api/dict'
  206. import { getProductDetail } from '@/api/product'
  207. import UploadComponent from '../common/upload-component-v2'
  208. import { dealStepData, dealStepLogs } from '@/api/util'
  209. import CusComponent from '../common/cus-component'
  210. import DrawComponents from '../common/draw-components'
  211. import DocComponents from '../common/doc-components'
  212. export default {
  213. name: 'product-add-or-update',
  214. components: { DocComponents, DrawComponents, CusComponent, UploadComponent, templateChose, templateChoseMaterial, templateDrawChoose },
  215. computed: {
  216. orgId: {
  217. get () { return this.$store.state.user.orgId }
  218. }
  219. },
  220. // watch: {
  221. // 'dataForm.isCompose' (value) {
  222. // this.dataForm.displayProductList = value === '1'
  223. // }
  224. // },
  225. data () {
  226. return {
  227. productListVisible: false,
  228. materialListVisible: false,
  229. drawListVisible: false,
  230. visible: false,
  231. display: false,
  232. optionsType: [],
  233. // optionsTech: [],
  234. fileList: [],
  235. listingList: [],
  236. dataList: [],
  237. id: 0,
  238. productDetails: [],
  239. materialList: [],
  240. drawingList: [],
  241. displayProductList: false,
  242. dataForm: {
  243. drawingList: []
  244. },
  245. dataRule: {
  246. productName: [{ required: true, message: '请输入物料名称', trigger: 'blur' }],
  247. productSpec: [{ required: true, message: '请输入物料规格', trigger: 'blur' }],
  248. productType: [{ required: true, message: '请选择物料类别', trigger: 'change' }],
  249. materials: [{ required: true, message: '请输入材料', trigger: 'blur' }],
  250. size: [{ required: true, message: '请输入物料尺寸', trigger: 'blur' }],
  251. unit: [{ required: true, message: '请输入单位', trigger: 'blur' }],
  252. cnt: [{ required: true, message: '请输入单套数量', trigger: 'blur' }],
  253. mapNumber: [{ required: true, message: '请输入主图号', trigger: 'blur' }]
  254. },
  255. stepList: [],
  256. logList: []
  257. }
  258. },
  259. methods: {
  260. onChose () {
  261. this.$emit('onChose')
  262. },
  263. async init (id, display) {
  264. this.fileList = []
  265. this.listingList = []
  266. this.stepList = []
  267. this.logList = []
  268. this.dataForm = {
  269. drawList: []
  270. }
  271. this.productDetails = []
  272. this.materialList = []
  273. // this.optionsTech = []
  274. // this.optionsDraw = []
  275. this.visible = true
  276. this.id = id || 0
  277. this.display = display
  278. // 获取物料类别
  279. await getDictList({ type: 'product_type' }).then(({ data }) => {
  280. if (data) {
  281. this.optionsType = data
  282. }
  283. })
  284. // 物料工艺
  285. if (!id) return
  286. await getProductDetail(this.id).then(({ data }) => {
  287. if (data && data.code === '200') {
  288. this.dataForm = data.data
  289. if (data.data.docs) {
  290. let docIdList = []
  291. data.data.docs.forEach((item) => {
  292. docIdList.push(item.docId)
  293. })
  294. this.dataForm.docIdList = docIdList
  295. }
  296. if (data.data.proDrawings) {
  297. let idList = []
  298. data.data.proDrawings.forEach((item) => {
  299. idList.push(item.drawingId)
  300. })
  301. this.dataForm.drawingIdList = idList
  302. }
  303. // 流程图展示
  304. if (data.data.workFlowBusinessExt) {
  305. dealStepData(data.data.workFlowBusinessExt.workFlowProcessStepList, this.stepList)
  306. dealStepLogs(data.data.workFlowBusinessExt.processLogList, this.logList)
  307. }
  308. // 组合小物料
  309. if (data.data.composeProductMaterialList) {
  310. data.data.composeProductMaterialList.forEach((item) => {
  311. this.productDetails.push({
  312. ...item,
  313. productSpec: item.specifications
  314. })
  315. })
  316. this.displayProductList = true
  317. }
  318. // 物料图纸
  319. this.drawingList = data.data.proDrawings || []
  320. }
  321. })
  322. },
  323. uploadSuccess (fileList) {
  324. this.fileList = fileList
  325. },
  326. uploadSuccess2 (fileList2) {
  327. this.listingList = fileList2
  328. },
  329. // 添加组合物料
  330. addProduct () {
  331. this.productListVisible = true
  332. this.$nextTick(() => {
  333. this.$refs.productList.init()
  334. })
  335. },
  336. addProductItems (items) {
  337. this.productDetails = []
  338. items.forEach((item) => {
  339. this.addProductItem(item)
  340. })
  341. },
  342. addProductItem (item) {
  343. this.productDetails.push({
  344. proProductId: item.productId,
  345. productName: item.productName,
  346. productSpec: item.productSpec,
  347. cnt: 1,
  348. notes: item.notes
  349. })
  350. },
  351. addMaterial () {
  352. this.materialListVisible = true
  353. this.$nextTick(() => {
  354. this.$refs.materialList.init()
  355. })
  356. },
  357. addMaterialItems (items) {
  358. this.materialList = []
  359. items.forEach((item) => {
  360. this.addMaterialItem(item)
  361. })
  362. },
  363. addMaterialItem (item) {
  364. this.materialList.push({
  365. ...item,
  366. cnt: 0
  367. })
  368. },
  369. validateField (type) {
  370. this.$refs.dataForm.validateField(type)
  371. },
  372. // 表单提交
  373. dataFormSubmit () {
  374. this.$refs['dataForm'].validate((valid) => {
  375. if (valid) {
  376. // 组合小物料
  377. this.dataForm.composeProductMaterialList = []
  378. const b1 = this.displayProductList
  379. this.dataForm.isCompose = b1 === true ? '1' : '0'
  380. if (this.dataForm.isCompose === '1' && this.productDetails.length > 0) {
  381. this.productDetails.forEach((item) => {
  382. this.dataForm.composeProductMaterialList.push({
  383. ...item
  384. })
  385. })
  386. }
  387. // if (this.drawingList.length <= 0) {
  388. // this.$message.error('请选择关联图纸')
  389. // return
  390. // }
  391. this.dataForm.drawingList = this.drawingList
  392. this.$http({
  393. url: !this.id ? this.$http.adornUrl(`/biz-service/product/save`) : this.$http.adornUrl(`/biz-service/product/update`),
  394. method: 'post',
  395. data: this.$http.adornData({ ...this.dataForm, orgId: this.orgId })
  396. }).then(({ data }) => {
  397. if (data && data.code === '200') {
  398. this.$message({
  399. message: '操作成功',
  400. type: 'success',
  401. duration: 1500,
  402. onClose: () => {
  403. this.onChose()
  404. this.$emit('refreshDataList')
  405. }
  406. })
  407. } else {
  408. this.$message.error(data.msg)
  409. }
  410. })
  411. } else {
  412. this.$message.error('请检查输入参数')
  413. }
  414. })
  415. },
  416. docSelectChange (val) {
  417. // console.log(val)
  418. this.dataForm.docIdList = val
  419. },
  420. // 添加关联图纸
  421. addDrawingList () {
  422. this.drawListVisible = true
  423. this.$nextTick(() => {
  424. this.$refs.drawList.init()
  425. })
  426. },
  427. addDrawItems (items) {
  428. items.forEach((item) => {
  429. this.addDrawItem(item)
  430. })
  431. },
  432. addDrawItem (item) {
  433. this.drawingList.push({
  434. drawingId: item.drawingId,
  435. drawingName: item.drawingName,
  436. drawingNo: item.drawingNo,
  437. source: item.source,
  438. notes: item.notes
  439. })
  440. },
  441. removeDrawingItem (index) {
  442. this.drawingList.splice(index, 1)
  443. },
  444. deleteProductHandle (proProductId) {
  445. this.productDetails.splice(this.productDetails.findIndex((item) => item.proProductId === proProductId), 1)
  446. }
  447. }
  448. }
  449. </script>
  450. <style scoped></style>