warehousingAdd.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="app-container">
  3. <el-form ref="dataForm" :model="dataForm" :rules="rules" label-width="120px" inline>
  4. <h3>通用入库单</h3>
  5. <!-- <el-form-item label="名称" prop="name">
  6. <el-input v-model="dataForm.name" :minlength="2" :maxlength="20" clearable
  7. placeholder="请输入名称" style="width:200px" :disabled="type === 'detail'"></el-input>
  8. </el-form-item> -->
  9. <el-form-item label="入库时间" prop="serialDate">
  10. <el-date-picker v-model="dataForm.serialDate" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
  11. placeholder="选择日期时间" style="width:200px" :disabled="type === 'detail'">
  12. </el-date-picker>
  13. </el-form-item>
  14. <el-form-item label="供应商" prop="supplierId">
  15. <el-select v-model="dataForm.supplierId" clearable placeholder="请选择" style="width: 200px;" :disabled="type === 'detail'">
  16. <el-option :key="item.id" v-for="item in supplierList" :label="item.businessName" :value="item.id">
  17. </el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item label="仓库" prop="warehouseId">
  21. <el-select v-model="dataForm.warehouseId" clearable placeholder="请选择" style="width: 200px;" :disabled="type === 'detail'">
  22. <el-option :key="item.id" v-for="item in warehouseList" :label="item.warehouseName" :value="item.id">
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="经手人" prop="addHandlerId">
  27. <el-select v-model="dataForm.addHandlerId" clearable filterable placeholder="请选择" style="width: 200px" :disabled="type === 'detail'">
  28. <el-option :key="item.loginId" v-for="item in recipientsList" :label="item.deptName+'_'+item.userName" :value="item.loginId">
  29. </el-option>
  30. </el-select>
  31. </el-form-item>
  32. <!-- <el-form-item label="采购说明" prop="desc">
  33. <el-input style="width:535px" v-model="dataForm.desc" :maxlength="120"
  34. type="textarea" :disabled="type === 'detail'" :autosize="{ minRows: 1, maxRows: 4 }"
  35. placeholder="请输入采购说明 最大120字"></el-input>
  36. </el-form-item> -->
  37. <el-form-item label="附件:" prop="fileIds">
  38. <el-upload :limit="1" :action="fileUrl" :file-list="dataForm.fileList" :on-success="handleFileSuccess"
  39. :before-upload="beforeUploadFile" :on-remove="handleRemove">
  40. <el-button size="small" type="primary" :disabled="type === 'detail'">点击上传</el-button>
  41. </el-upload>
  42. </el-form-item>
  43. <div class="mx">
  44. <h3>入库明细</h3>
  45. <el-button size="small" type="primary" v-if="type !== 'detail'"
  46. @click="handleSelectGoods" icon="el-icon-plus">商品/物料</el-button>
  47. </div>
  48. <el-table size="small" :data="dataForm.inventoryEntryInfos" border :cell-style="{ textAlign: 'center' }"
  49. :header-cell-style="{ textAlign: 'center' }" style="width: 100%">
  50. <el-table-column label="商品编号">
  51. <template slot-scope="scope">
  52. {{ scope.row.productCode }}
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="商品名称">
  56. <template slot-scope="scope">
  57. {{ scope.row.productName }}
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="单价(¥)">
  61. <template slot-scope="scope">
  62. {{ scope.row.createPrice.toFixed(2) }}
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="库存数量">
  66. <template slot-scope="scope">
  67. {{ scope.row.createProductNumber }}
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="入库数量">
  71. <template slot-scope="scope">
  72. <el-form-item v-if="type !== 'detail'" :prop="'inventoryEntryInfos.'+scope.$index+'.updateNumber'" :rules="{ required: true, message: '入库数量不能为空', trigger: 'blur' }" class="tableFormItem">
  73. <el-input-number v-model="scope.row.updateNumber" @change="handleChange(scope.row)" size="small" :min="1" :max="10000" label="入库数量"></el-input-number>
  74. </el-form-item>
  75. <span v-else>{{ scope.row.updateNumber }}</span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="合计(¥)">
  79. <template slot-scope="scope">
  80. {{ scope.row.sumPrice.toFixed(2) }}
  81. </template>
  82. </el-table-column>
  83. <!-- <el-table-column label="备注">
  84. <template slot-scope="scope">
  85. <el-input :maxlength="99" v-model="scope.row.remark" :disabled="type === 'detail'" />
  86. </template>
  87. </el-table-column> -->
  88. <el-table-column label="操作" width="150" v-if="type !== 'detail'">
  89. <template slot-scope="scope">
  90. <el-button size="mini" type="danger"
  91. @click="dataForm.inventoryEntryInfos.splice(scope.$index, 1)">删除</el-button>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. </el-form>
  96. <div class="footer">
  97. <el-button type="primary" @click="submitForm" v-if="type !== 'detail'">保存
  98. </el-button>
  99. <el-button @click="roBack()">返回
  100. </el-button>
  101. </div>
  102. </div>
  103. </template>
  104. <script>
  105. import { createWarehousing, updateWarehousing, readWarehousing } from "@/api/warehousing";
  106. import { supplierList } from "@/api/supplier";
  107. import { warehouseList } from "@/api/warehouse";
  108. import { allUserList } from "@/api/public";
  109. import waves from "@/directive/waves"; // 水波纹指令
  110. export default {
  111. directives: { waves },
  112. data() {
  113. return {
  114. fileUrl:this.upLoadUrl,
  115. recipientsList:[],
  116. supplierList: [],
  117. warehouseList: [],
  118. id: '',
  119. type: '',
  120. /** 表单*/
  121. dataForm: {
  122. serialDate:'',
  123. supplierId:undefined,
  124. warehouseId:undefined,
  125. addHandlerId:undefined,
  126. fileIds:undefined,
  127. fileList: [],
  128. inventoryEntryInfos: []
  129. },
  130. rules: {
  131. serialDate: [
  132. { required: true, message: '请选择入库时间', trigger: 'blur' }
  133. ],
  134. warehouseId: [
  135. { required: true, message: '请选择仓库', trigger: 'blur' }
  136. ],
  137. addHandlerId: [
  138. { required: true, message: '请选择经手人', trigger: 'blur' }
  139. ],
  140. },
  141. }
  142. },
  143. watch: {
  144. $route: {
  145. immediate: true,
  146. handler(newVal) {
  147. if (this.$route.name === 'warehousingAdd') {
  148. this.dataForm = {
  149. serialDate:undefined,
  150. supplierId:undefined,
  151. warehouseId:undefined,
  152. addHandlerId:undefined,
  153. fileIds:undefined,
  154. fileList: [],
  155. inventoryEntryInfos: []
  156. }
  157. } else if (this.$route.name === 'warehousingDetail') {
  158. this.type = 'detail'
  159. }
  160. if (this.$route.params.id) {
  161. this.id = this.$route.params.id
  162. this.getDataFormDetail()
  163. }
  164. }
  165. }
  166. },
  167. mounted() {
  168. this.getSupplierList();
  169. this.getStoreList();
  170. this.getAllUserList();
  171. },
  172. methods: {
  173. /** 获取供应商列表数据 */
  174. getSupplierList(){
  175. supplierList().then(response => {
  176. this.supplierList = response.data.data;
  177. }).catch(() => { });
  178. },
  179. /** 获取仓库列表数据 */
  180. getStoreList() {
  181. warehouseList().then(response => {
  182. this.warehouseList = response.data.data;
  183. }).catch(() => {});
  184. },
  185. /** 获取人员列表数据 */
  186. getAllUserList() {
  187. allUserList().then(response => {
  188. this.recipientsList = response.data.data;
  189. }).catch(() => { });
  190. },
  191. /** 获取详情页面数据 */
  192. getDataFormDetail() {
  193. readWarehousing({ id: this.id }).then(response => {
  194. let dataForm = response.data.data;
  195. dataForm.inventoryEntryInfos = dataForm.inventoryEntryInfos == null ? [] : dataForm.inventoryEntryInfos
  196. dataForm.inventoryOutInfos = dataForm.inventoryOutInfos == null ? [] : dataForm.inventoryOutInfos
  197. this.dataForm = dataForm;
  198. this.dataForm.fileList = dataForm.files == null ? [] : dataForm.files;
  199. }).catch(() => {})
  200. },
  201. // 选择商品
  202. async handleSelectGoods() {
  203. if (!this.dataForm.warehouseId) {
  204. this.$message.error('请先选择仓库!')
  205. return
  206. }else{
  207. console.log(this.dataForm.inventoryEntryInfos)
  208. let selectedIds = this.dataForm.inventoryEntryInfos.map(item => item.id);
  209. const Goods = await this.$EnPickerGoods({
  210. // goodsApi: '/warehouse-entry/info/inventory',
  211. selectedIds: selectedIds,
  212. goodsApiParams: { warehouseId: this.dataForm.warehouseId, type:'1' }
  213. })
  214. if (!Goods.length) return
  215. const inventoryEntryInfos = Goods.map(item => {
  216. item.updateNumber = 1
  217. item.sumPrice = item.createPrice * 1
  218. return item
  219. })
  220. this.dataForm.inventoryEntryInfos = this.dataForm.inventoryEntryInfos && this.dataForm.inventoryEntryInfos.length ? this.dataForm.inventoryEntryInfos.concat(inventoryEntryInfos) : this.dataForm.inventoryEntryInfos = inventoryEntryInfos
  221. }
  222. },
  223. submitForm(){
  224. this.$refs["dataForm"].validate((valid) => {
  225. if (valid) {
  226. if(this.dataForm.inventoryEntryInfos.length == 0){
  227. this.$message.error('请选择商品/物料!')
  228. return
  229. }else{
  230. if(this.id){
  231. updateWarehousing(this.dataForm).then(() => {
  232. this.$notify({
  233. title: '成功',
  234. message: '更新成功',
  235. type: 'success',
  236. duration: 2000
  237. })
  238. this.roBack();
  239. })
  240. }else{
  241. createWarehousing(this.dataForm).then(() => {
  242. this.$notify({
  243. title: "成功",
  244. message: "创建成功",
  245. type: "success",
  246. duration: 2000,
  247. });
  248. this.roBack();
  249. })
  250. }
  251. }
  252. }
  253. });
  254. },
  255. handleChange(row) {
  256. if (row.createPrice && row.updateNumber) {
  257. row.sumPrice = row.createPrice * row.updateNumber
  258. }
  259. },
  260. roBack() {
  261. // const { callback } = this.$route.params
  262. // if (typeof callback === 'function') callback()
  263. this.$store.dispatch('delVisitedViews', this.$route).then((views) => {
  264. const latestView = views.slice(-1)[0]
  265. if (latestView) {
  266. this.$router.push(latestView.path)
  267. } else {
  268. this.$router.push('/')
  269. }
  270. })
  271. // this.$router.push({ name: 'warehousing' })
  272. },
  273. handleRemove(file, fileList) {
  274. console.log(file, fileList);
  275. let fileIds = [];
  276. for (let i in fileList) {
  277. let id = fileList[i].response.data.id;
  278. fileIds.push(id);
  279. }
  280. this.dataForm.fileIds = fileIds.join(",");
  281. },
  282. beforeUploadFile(file) {
  283. console.log(file);
  284. const size = file.size / 1024 / 1024;
  285. console.log(size);
  286. if (size > 10) {
  287. this.$message.error("文件大小不能超过10MB!");
  288. return false;
  289. }
  290. },
  291. handleFileSuccess(res, file, fileList) {
  292. console.log(file, fileList);
  293. console.log("------", "==========");
  294. console.log("res = ", res);
  295. let fileIds = [];
  296. for (let i in fileList) {
  297. let response = fileList[i].response;
  298. if (response.errno && response.errno != "0") {
  299. this.$message.error("该文件上传失败,已被移除,请重新上传!");
  300. // 上传失败移除该 file 对象
  301. fileList.splice(i, 1);
  302. } else {
  303. let id = fileList[i].response.data.id;
  304. fileIds.push(id);
  305. }
  306. }
  307. this.dataForm.fileIds = fileIds.join(",");
  308. },
  309. }
  310. }
  311. </script>
  312. <style>
  313. /** 底部步骤 */
  314. .footer {
  315. width: 100%;
  316. padding: 10px;
  317. bottom: 0px;
  318. text-align: center;
  319. z-index: 999;
  320. }
  321. .mx {
  322. display: flex;
  323. align-items: center;
  324. justify-content: space-between;
  325. }
  326. /** 表格中输入框样式 */
  327. .tableFormItem {
  328. width: 100%;
  329. margin-bottom: 0;
  330. }
  331. </style>