warehousingAdd.vue 15 KB

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