requisitionAdd.vue 15 KB

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