stock-order-inbound.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <!-- 入库申请 -->
  2. <template>
  3. <div>
  4. <div class="my-title">{{ !display ? '入库申请':'详情' }}</div>
  5. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="auto">
  6. <el-row class="my-row my-row-1">
  7. <el-col :span="8">
  8. <el-form-item label="编码" prop="recordCode">
  9. <el-input v-model="dataForm.recordCode" :disabled="true" placeholder="编码系统自动生成"></el-input>
  10. </el-form-item>
  11. </el-col>
  12. </el-row>
  13. <template v-for="(item, index) in dataList">
  14. <div :key="index" class="my-line">
  15. <el-row class="my-row">
  16. <el-col :span="24" style="text-align: right;">
  17. <el-button v-if="!display" @click="removeOne(index)" type="danger" icon="el-icon-delete" circle style="padding: 6px"></el-button>
  18. </el-col>
  19. </el-row>
  20. <el-row class="my-row">
  21. <el-col :span="8">
  22. <el-form-item label="名称" prop="materialId" :rules="{required: false, message: '名称不能为空', trigger: 'blur'}">
  23. <el-input v-if="item.buttonType === '1'" placeholder="请输入" v-model="item.materialName"
  24. :disabled="display" style="width: 200px; margin-right: 10px"/>
  25. <material-component v-else
  26. v-model="dataList[index]"
  27. :material-id="item.materialId">
  28. </material-component>
  29. <el-button v-show="item.buttonType && item.buttonType === '1'" @click="changeButtonType(item, 0)" type="danger">选择</el-button>
  30. <el-button v-show="!item.buttonType || item.buttonType === '0'" @click="changeButtonType(item, 1)" type="danger">输入</el-button>
  31. </el-form-item>
  32. </el-col>
  33. <el-col :span="8" style="padding-left: 20px">
  34. <el-form-item label="类别" prop="materialTypeId" :rules="{required: false, message: '类别不能为空', trigger: 'blur'}">
  35. <el-input v-if="!item.buttonType || item.buttonType === '0'" v-model="item.categoryName" :disabled="true" style="width: 200px"></el-input>
  36. <material-type-component v-else v-model="item.materialTypeId" :type-id.sync="item.materialTypeId"></material-type-component>
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="8" style="padding-left: 20px">
  40. <el-form-item label="入库依据类别" prop="sourceCategory" :rules="{required: false, message: '类别不能为空', trigger: 'blur'}">
  41. <el-select v-model="item.sourceCategory" placeholder="请选择">
  42. <el-option
  43. v-for="item in optionsSourceCategory"
  44. :key="item.code"
  45. :label="item.value"
  46. :value="item.code">
  47. </el-option>
  48. </el-select>
  49. </el-form-item>
  50. </el-col>
  51. </el-row>
  52. <el-row class="my-row">
  53. <el-col :span="8">
  54. <el-form-item label="单位" prop="unitName" :rules="{required: false, message: '单位不能为空', trigger: 'blur'}">
  55. <el-input v-model="item.unitName" :disabled="display || !item.buttonType || item.buttonType === '0'" placeholder="单位"></el-input>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="8" style="padding-left: 20px">
  59. <el-form-item label="规格" prop="specifications" :rules="{required: false, message: '规格不能为空', trigger: 'blur'}">
  60. <el-input v-model="item.specifications" :disabled="display || !item.buttonType || item.buttonType === '0'" placeholder="规格"></el-input>
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="8" style="padding-left: 20px">
  64. <el-form-item label="批次号" prop="batchNumber" :rules="{required: false, message: '批次号不能为空', trigger: 'blur'}">
  65. <el-input v-model="item.batchNumber" :disabled="display" placeholder="请填写入库物品(零件)批次"></el-input>
  66. </el-form-item>
  67. </el-col>
  68. </el-row>
  69. <el-row class="my-row">
  70. <el-col :span="8">
  71. <el-form-item label="单价" prop="price">
  72. <el-input-number v-model="item.price" :disabled="display" :precision="1" :min="0.0" :step="0.1"></el-input-number>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="8" style="padding-left: 20px">
  76. <el-form-item label="数量" prop="cnt">
  77. <el-input-number v-model="item.cnt" :disabled="display" :min="0"></el-input-number>
  78. </el-form-item>
  79. </el-col>
  80. <el-col :span="8" style="padding-left: 20px">
  81. <el-form-item label="金额" prop="amount">
  82. <span>{{ item.price * item.cnt }}</span>
  83. </el-form-item>
  84. </el-col>
  85. </el-row>
  86. <el-row class="my-row">
  87. <el-col :span="8">
  88. <el-form-item label="来源" prop="source">
  89. <el-input v-model="item.source" :disabled="display" placeholder="来源"></el-input>
  90. </el-form-item>
  91. </el-col>
  92. <el-col :span="8" style="padding-left: 20px">
  93. <el-form-item label="是否换算" prop="unitNeedChange">
  94. <convert-component v-model="item.unitNeedChange" :convert-id="item.unitNeedChange"></convert-component>
  95. </el-form-item>
  96. </el-col>
  97. </el-row>
  98. <el-row>
  99. <el-form-item label="备注" prop="notes">
  100. <el-input type="textarea" v-model="item.notes" :disabled="display"></el-input>
  101. </el-form-item>
  102. </el-row>
  103. </div>
  104. </template>
  105. <el-row style="text-align: center;">
  106. <el-button v-if="!display" type="primary" icon="el-icon-plus" @click="addOne"></el-button>
  107. </el-row>
  108. </el-form>
  109. <span v-if="!display" slot="footer" class="dialog-footer">
  110. <el-button @click="onChose">取消</el-button>
  111. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  112. </span>
  113. </div>
  114. </template>
  115. <script>
  116. import UserComponent from '../common/user-component'
  117. import DictSelect from '../sys/dict-select'
  118. import { inboundBatch, getBoundDetails } from '@/api/warehouse'
  119. import ConvertComponent from '../common/convert-component'
  120. import MaterialComponent from '../common/material-component'
  121. import MaterialTypeComponent from '../common/material-type-component'
  122. export default {
  123. name: 'stock-order-inbound',
  124. components: {MaterialTypeComponent, MaterialComponent, ConvertComponent, DictSelect, UserComponent},
  125. data () {
  126. return {
  127. visible: false,
  128. display: false,
  129. id: 0,
  130. dataForm: {},
  131. dataList: [],
  132. dataRule: {
  133. userId: [{ required: true, message: '请选择入库申请人', trigger: 'blur' }]
  134. },
  135. optionsSourceCategory: [
  136. {code: '1', value: '采购入库'},
  137. {code: '2', value: '生产入库'},
  138. {code: '3', value: '委外入库'}
  139. ]
  140. }
  141. },
  142. methods: {
  143. onChose () {
  144. this.$emit('onChose')
  145. },
  146. async init (id, display, dataForm) {
  147. // console.log(dataForm)
  148. this.display = display
  149. this.id = id || 0
  150. this.visible = true
  151. this.dataForm = {}
  152. this.dataList = []
  153. if (dataForm) {
  154. this.addOne(dataForm)
  155. } else if (!display) {
  156. this.addOne()
  157. } else {
  158. // 获取详情
  159. await getBoundDetails(id).then(({data}) => {
  160. if (data && data.code === '200') {
  161. if (data.data[0]) {
  162. this.dataForm = {
  163. recordCode: data.data[0].recordCode,
  164. applicant: data.data[0].applicant,
  165. orgName: data.data[0].orgName
  166. }
  167. }
  168. data.data.forEach((item) => {
  169. this.addOne(item)
  170. })
  171. }
  172. })
  173. }
  174. },
  175. addOne (item) {
  176. this.dataList.push({...item,
  177. buttonType: item ? (item.buttonType ? '1' : '0') : '0',
  178. // id: item ? item.id : '',
  179. amount: item ? item.amount : 0,
  180. // applicant: item ? item.applicant : '',
  181. // approver: item ? item.approver : '',
  182. // unitName: item ? item.unitName : '',
  183. // specifications: item ? item.specifications : '',
  184. // batchNumber: item ? item.batchNumber : '',
  185. // cnt: item ? item.cnt : '',
  186. // categoryName: item ? item.categoryName : '',
  187. // materialId: item ? item.materialId : '',
  188. // materialName: item ? item.materialName : '',
  189. // notes: item ? item.notes : '',
  190. // orgId: item ? item.orgId : '',
  191. // price: item ? item.price : '',
  192. // recordType: item ? item.recordType : '',
  193. // source: item ? item.source : '',
  194. state: item ? item.state : 0,
  195. // templateItemPlanId: item ? item.templateItemPlanId : '',
  196. // usage: item ? item.usage : '',
  197. // userId: item ? item.userId : '',
  198. // orgName: item ? item.orgName : '',
  199. // unitNeedChange: item ? item.unitNeedChange : '',
  200. // conversionName: item ? item.conversionName : '',
  201. sourceCategory: item ? item.sourceCategory : '2'
  202. // materialTypeId: item ? item.materialTypeId : '',
  203. // tableId: item ? item.tableId : null
  204. })
  205. },
  206. removeOne (index) {
  207. this.dataList.splice(index, 1)
  208. if (this.dataList.length === 0) {
  209. this.addOne()
  210. }
  211. },
  212. // 表单提交
  213. dataFormSubmit () {
  214. this.$refs['dataForm'].validate((valid) => {
  215. if (valid) {
  216. let postData = []
  217. this.dataList.forEach((item) => {
  218. postData.push({...item,
  219. // amount: item.amount,
  220. applicant: this.dataForm.userId,
  221. // approver: item.approver,
  222. // batchNumber: item.batchNumber,
  223. // cnt: item.cnt,
  224. // materialId: item.materialId,
  225. materialName: item.materialName ? item.materialName : item.materialId,
  226. materialTypeId: item.materialTypeId ? item.materialTypeId : item.cateId,
  227. // notes: item.notes,
  228. orgId: this.$store.state.user.orgId,
  229. // price: item.price,
  230. recordCode: this.dataForm.recordCode,
  231. recordType: this.dataForm.recordType,
  232. // source: item.source,
  233. // specifications: item.specifications,
  234. // unitName: item.unitName,
  235. // unitNeedChange: item.unitNeedChange,
  236. userId: this.$store.state.user.id
  237. // sourceCategory: item.sourceCategory
  238. })
  239. })
  240. inboundBatch(postData).then(({data}) => {
  241. if (data && data.code === '200') {
  242. this.$message({
  243. message: '操作成功',
  244. type: 'success',
  245. duration: 1500,
  246. onClose: () => {
  247. this.onChose()
  248. this.$emit('refreshDataList')
  249. }
  250. })
  251. } else {
  252. this.$message.error(data.msg)
  253. }
  254. })
  255. }
  256. })
  257. },
  258. validateField (type) {
  259. this.$refs.dataForm.validateField(type)
  260. },
  261. // 切换按钮状态
  262. changeButtonType (item, type) {
  263. if (!item) return
  264. item.buttonType = type === 0 ? '0' : '1'
  265. this.$nextTick(() => {
  266. this.$forceUpdate()
  267. })
  268. }
  269. }
  270. }
  271. </script>
  272. <style scoped>
  273. .my-line{
  274. border-bottom: 1px solid #c0c4cc;
  275. margin-bottom: 10px;
  276. }
  277. .my-row-1{
  278. margin-bottom: 20px;
  279. }
  280. </style>