addInventory.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. <template>
  2. <div class="bg-in-stock">
  3. <el-form
  4. ref="goodsExchangeAddForm"
  5. :model="goodsExchangeAddForm"
  6. :rules="goodsExchangeAddFormRule"
  7. label-width="160px"
  8. inline
  9. class="change-form"
  10. >
  11. <el-form-item label="订单" prop="sn" class="change-form-item">
  12. <el-input
  13. v-model="goodsExchangeAddForm.sn"
  14. :disabled="type === 'detail' || type === 'audit'"
  15. ref="order"
  16. @blur="blurUsername()"
  17. >
  18. </el-input>
  19. </el-form-item>
  20. <el-form-item prop="warehouse_id" label="入库仓库" class="change-form-item">
  21. <el-select
  22. v-model="goodsExchangeAddForm.warehouse_id"
  23. clearable
  24. :disabled="type === 'detail' || type === 'audit'"
  25. >
  26. <!-- @change="handleChangeWareHouse" -->
  27. <el-option
  28. v-for="item in warehouseList"
  29. :key="item.id"
  30. :label="item.name"
  31. :value="item.id"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item label="类型" prop="type" class="change-form-item">
  36. <el-select
  37. v-model="goodsExchangeAddForm.type"
  38. filterable
  39. allow-create
  40. clearable
  41. default-first-option
  42. :disabled="type === 'detail' || type === 'audit'"
  43. >
  44. <el-option
  45. v-for="item in typeList"
  46. :key="item.id"
  47. :label="item.real_name"
  48. :value="item.id"
  49. />
  50. </el-select>
  51. </el-form-item>
  52. <el-form-item
  53. label="备注"
  54. prop="change_desc"
  55. class="change-form-item"
  56. style="width: 61%"
  57. >
  58. <el-input
  59. style="flex: 1"
  60. v-model="goodsExchangeAddForm.memo"
  61. type="textarea"
  62. :disabled="type === 'detail' || type === 'audit'"
  63. :autosize="{ minRows: 3, maxRows: 4 }"
  64. placeholder="请输入"
  65. ></el-input>
  66. </el-form-item>
  67. <div class="mx">
  68. <h3>商品明细</h3>
  69. <el-button
  70. class="button"
  71. size="mini"
  72. type="primary"
  73. v-if="type !== 'detail' && type !== 'audit'"
  74. @click="scanCode"
  75. >扫码入库</el-button
  76. >
  77. <el-button
  78. class="button"
  79. size="mini"
  80. type="primary"
  81. v-if="type !== 'detail' && type !== 'audit'"
  82. @click="handleSelectWarehouseEntryBatch"
  83. >选择</el-button
  84. >
  85. </div>
  86. <div style="width: 100%; display: block">
  87. <el-form-item style="width: 100%">
  88. <el-table
  89. :data="goodsExchangeAddForm.product_list"
  90. border
  91. :cell-style="{ textAlign: 'center' }"
  92. :header-cell-style="{ textAlign: 'center' }"
  93. style="width: 100%; margin-top: 20px"
  94. >
  95. <el-table-column label="商品编号">
  96. <template slot-scope="scope">
  97. {{ scope.row.sn }}
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="商品名称">
  101. <template slot-scope="scope">
  102. {{ scope.row.name }}
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="条码">
  106. <template slot-scope="scope">
  107. {{ scope.row.product_barcode }}
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="序列号">
  111. <template slot-scope="scope">
  112. {{ scope.row.sn_code }}
  113. </template>
  114. </el-table-column>
  115. <el-table-column label="规格型号">
  116. <template slot-scope="scope">
  117. {{ scope.row.goods_style }}
  118. </template>
  119. </el-table-column>
  120. <el-table-column label="单位">
  121. <template slot-scope="scope">
  122. {{ scope.row.goods_unit }}
  123. </template>
  124. </el-table-column>
  125. <!-- <el-table-column label="订单数量">
  126. </el-table-column> -->
  127. <el-table-column label="入库数量">
  128. <template slot-scope="scope">
  129. <el-input
  130. v-model="scope.row.num"
  131. type="number"
  132. :min="0"
  133. :maxlength="20"
  134. :disabled="type === 'detail' || type === 'audit'"
  135. ></el-input>
  136. </template>
  137. </el-table-column>
  138. <el-table-column label="库存数量">
  139. <template slot-scope="scope">
  140. {{ scope.row.usable_stock }}
  141. </template>
  142. </el-table-column>
  143. <el-table-column label="差异">
  144. <template slot-scope="scope">
  145. <!-- 入库减去库存 -->
  146. {{ scope.row.num - scope.row.usable_stock || 0 }}
  147. </template>
  148. </el-table-column>
  149. <el-table-column
  150. label="操作"
  151. v-if="type !== 'detail' && type !== 'audit'"
  152. >
  153. <template slot-scope="scope">
  154. <el-button
  155. size="mini"
  156. type="danger"
  157. @click="
  158. goodsExchangeAddForm.product_list.splice(
  159. scope.$index,
  160. 1
  161. )
  162. "
  163. >删除</el-button
  164. >
  165. </template>
  166. </el-table-column>
  167. </el-table>
  168. </el-form-item>
  169. </div>
  170. </el-form>
  171. <div class="footer">
  172. <!-- <el-button v-if="type === 'audit'" type="primary" @click="handlePassGoodsExchange()">审核通过
  173. </el-button>
  174. <el-button v-if="type === 'audit'" type="danger" @click="dialogVisible = true">审核驳回
  175. </el-button> -->
  176. <el-button
  177. v-if="type !== 'audit' && type !== 'detail'"
  178. type="primary"
  179. @click="savegoodsExchangeAddForm"
  180. >保存
  181. </el-button>
  182. <el-button
  183. v-if="type !== 'audit' && type !== 'detail'"
  184. type="primary"
  185. @click="submitgoodsExchangeAddForm"
  186. >入库
  187. </el-button>
  188. <el-button @click="printIng" v-if="type == 'audit'">打印</el-button>
  189. <el-button @click="$router.back()">返回</el-button>
  190. </div>
  191. <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
  192. <el-form
  193. ref="goodsExchangeAddForm"
  194. :model="goodsExchangeAddForm"
  195. label-width="120px"
  196. inline
  197. style="width: 900px"
  198. >
  199. <el-form-item label="驳回原因" prop="reject_reason">
  200. <el-input
  201. v-model="goodsExchangeAddForm.reject_reason"
  202. type="textarea"
  203. :minlength="0"
  204. :maxlength="100"
  205. ></el-input>
  206. </el-form-item>
  207. </el-form>
  208. <span slot="footer" class="dialog-footer">
  209. <el-button @click="dialogVisible = false">取 消</el-button>
  210. <el-button type="primary" @click="handleRejectGoodsExchange()"
  211. >确 定</el-button
  212. >
  213. </span>
  214. </el-dialog>
  215. <el-dialog title="扫码入库" :visible.sync="scanDialogVisible" width="30%">
  216. <el-form
  217. ref="scanGoodsForm"
  218. :model="scanGoodsForm"
  219. label-width="120px"
  220. inline
  221. >
  222. <el-form-item label="条码" prop="bar_code">
  223. <el-input
  224. v-model="scanGoodsForm.bar_code"
  225. ref="input"
  226. @keyup.enter.native="toSearch()"
  227. @blur="blurCode()"
  228. :minlength="0"
  229. :maxlength="100"
  230. ></el-input>
  231. </el-form-item>
  232. <el-form-item label="序列号" prop="sn_code">
  233. <el-input
  234. v-model="scanGoodsForm.sn_code"
  235. :minlength="0"
  236. :maxlength="100"
  237. ></el-input>
  238. </el-form-item>
  239. </el-form>
  240. <span slot="footer" class="dialog-footer">
  241. <!-- <el-button @click="dialogVisible = false">取 消</el-button>
  242. <el-button type="primary" @click="handleRejectGoodsExchange()">确 定</el-button> -->
  243. </span>
  244. </el-dialog>
  245. <el-dialog
  246. title="入库商品"
  247. :visible.sync="goodsVisible"
  248. width="1000px"
  249. @close="closeGoosData"
  250. >
  251. <el-table
  252. :data="goodsData"
  253. border
  254. style="width: 100%"
  255. @selection-change="handleSelectionChange"
  256. >
  257. <el-table-column type="selection" width="55" />
  258. <el-table-column prop="sn" label="商品编号"> </el-table-column>
  259. <el-table-column prop="bar_code" label="商品条码"> </el-table-column>
  260. <el-table-column prop="sn_code" label="序列号"> </el-table-column>
  261. <el-table-column prop="name" label="商品名称"> </el-table-column>
  262. <el-table-column prop="goods_style" label="规格型号"> </el-table-column>
  263. <el-table-column prop="goods_unit" label="单位"> </el-table-column>
  264. <!-- <el-table-column prop="product_list.stock_num" label="库存数量"> </el-table-column> -->
  265. </el-table>
  266. <span slot="footer" class="dialog-footer">
  267. <el-button @click="closeGoosData">取 消</el-button>
  268. <el-button type="primary" @click="submitGoosData()">确 定</el-button>
  269. </span>
  270. </el-dialog>
  271. </div>
  272. </template>
  273. <script>
  274. import { mapGetters } from "vuex";
  275. import { Foundation, RegExp } from "~/ui-utils";
  276. import * as API_GoodsExchange from "@/api/goodsExchange";
  277. import * as API_Setting from "@/api/setting";
  278. import * as API_BasicSetting from "@/api/basicSetting";
  279. import * as API_Erp from "@/api/erp";
  280. import * as API_Auth from "@/api/auth";
  281. import * as API_order from "@/api/order";
  282. import * as API_Goods from "@/api/goods";
  283. export default {
  284. name: "goodsExchangeAdd",
  285. data() {
  286. const checkPrice = (rule, value, callback) => {
  287. if (!value && value !== 0) {
  288. return callback(new Error("换货金额不能为空"));
  289. } else if (!RegExp.money.test(value)) {
  290. callback(new Error("请输入正整数或者两位小数"));
  291. } else if (parseFloat(value) > 99999999) {
  292. callback(new Error("换货金额设置超过上限值"));
  293. } else {
  294. callback();
  295. }
  296. };
  297. return {
  298. typeList: [
  299. {
  300. real_name: "采购入库",
  301. id: "采购入库",
  302. },
  303. {
  304. real_name: "租赁返回",
  305. id: "租赁返回",
  306. },
  307. {
  308. real_name: "其他入库",
  309. id: "其他入库",
  310. },
  311. ],
  312. adminList: [],
  313. dialogVisible: false,
  314. warehouseList: [],
  315. deptList: [],
  316. deptListAll: [],
  317. orderList: [],
  318. id: "",
  319. type: "",
  320. /** 入库单表单*/
  321. goodsExchangeAddForm: {
  322. contract_product_list: [],
  323. /* additionalProp1: {
  324. barcode: "string",
  325. category_id: 0,
  326. category_name: "string",
  327. contract_id: 0,
  328. goods_id: 0,必填
  329. num: 0,
  330. price: 0,
  331. product_id: 0,//必填
  332. product_name: "string",
  333. product_sn: "string",
  334. specification: "string",
  335. stock_num: 0,
  336. tax_rate: 0,
  337. total_price: 0,
  338. unit: "string",
  339. },
  340. additionalProp2: {
  341. barcode: "string",
  342. category_id: 0,
  343. category_name: "string",
  344. contract_id: 0,
  345. goods_id: 0,
  346. num: 0,
  347. price: 0,
  348. product_id: 0,
  349. product_name: "string",
  350. product_sn: "string",
  351. specification: "string",
  352. stock_num: 0,
  353. tax_rate: 0,
  354. total_price: 0,
  355. unit: "string",
  356. },
  357. additionalProp3: {
  358. barcode: "string",
  359. category_id: 0,
  360. category_name: "string",
  361. contract_id: 0,
  362. goods_id: 0,
  363. num: 0,
  364. price: 0,
  365. product_id: 0,
  366. product_name: "string",
  367. product_sn: "string",
  368. specification: "string",
  369. stock_num: 0,
  370. tax_rate: 0,
  371. total_price: 0,
  372. unit: "string",
  373. }, */
  374. product_list: [],
  375. },
  376. /** 校验规则 */
  377. goodsExchangeAddFormRule: {
  378. warehouse_id: [
  379. { required: true, message: "请选择入库仓库", trigger: "change" },
  380. ],
  381. type: [
  382. { required: true, message: "请选择入库类型", trigger: "change" },
  383. ],
  384. // order_id: [
  385. // { required: true, message: "请输入订单编号", trigger: "blur" },
  386. // ],
  387. // change_amount: [
  388. // { required: true, message: '请输入换货金额', trigger: 'blur' },
  389. // { validator: checkPrice, trigger: 'blur' }
  390. // ]
  391. },
  392. warehouseProduct: null,
  393. scanDialogVisible: false,
  394. scanGoodsForm: {},
  395. routeName: "",
  396. //出入库
  397. sttorageType: "",
  398. // 出库商品明细
  399. goodsVisible: false,
  400. goodsData: [],
  401. // 暂存已勾选商品
  402. goodsList: [],
  403. };
  404. },
  405. mounted() {
  406. this.$nextTick(() => {
  407. this.$refs.order.focus();
  408. });
  409. this.routeName = this.$route.name;
  410. this.sttorageType = this.$route.params.type;
  411. this.GET_WarehouseList();
  412. this.GET_DeptList();
  413. },
  414. watch: {
  415. $route: {
  416. immediate: true,
  417. handler(newVal) {
  418. if (this.$route.name === "goodsExchangeEdit") {
  419. this.type = "edit";
  420. } else if (this.$route.name === "goodsExchangeAudit") {
  421. this.type = "audit";
  422. } else if (this.$route.name === "goodsExchangeReturn") {
  423. this.type = "return";
  424. } else if (this.$route.name === "goodsExchangeAdd") {
  425. this.type = "add";
  426. this.goodsExchangeAddForm = {
  427. change_amount: 0,
  428. change_list: [],
  429. return_list: [],
  430. product_list: [],
  431. handled_by_id: this.user.uid,
  432. dept_id: this.user.dept_id,
  433. };
  434. // this.goodsExchangeAddForm.handled_by_id = this.user.uid
  435. // this.goodsExchangeAddForm.dept_id = this.user.dept_id
  436. this.GET_WarehouseList({ dept_id: this.user.dept_id });
  437. this.$set(
  438. this.goodsExchangeAddForm,
  439. "change_time",
  440. new Date().getTime()
  441. );
  442. } else if (this.$route.name === "goodsExchangeDetail") {
  443. this.type = "detail";
  444. }
  445. if (this.$route.params.id) {
  446. this.id = this.$route.params.id;
  447. this.GET_goodsExchangeAddDetail();
  448. }
  449. this.GET_AdministratorList();
  450. },
  451. },
  452. },
  453. computed: {
  454. ...mapGetters(["user"]),
  455. },
  456. methods: {
  457. // 根据条码 序列号查询商品
  458. blurCode(){
  459. if(this.scanGoodsForm.bar_code!==undefined || this.scanGoodsForm.sn_code!==undefined){
  460. // 通过列表查询商品详细信息
  461. API_Goods.getGoodsList({barcode:this.scanGoodsForm.bar_code,sncode:this.scanGoodsForm.sn_code}).then(res=>{
  462. console.log(res);
  463. this.goodsExchangeAddForm.contract_product_list=res.data
  464. this.scanDialogVisible=false
  465. })
  466. }
  467. },
  468. // 查询订单编号
  469. blurUsername(){
  470. if(this.goodsExchangeAddForm.sn!==undefined){
  471. API_order.getOrderList({sn:this.goodsExchangeAddForm.sn}).then(res=>{
  472. console.log(res.data);
  473. this.goodsExchangeAddForm.order_id= Number(res.data[0].id)
  474. this.goodsExchangeAddForm.contract_product_list=res.data
  475. })
  476. }/* else{
  477. this.$message.error("请填写订单编号")
  478. } */
  479. },
  480. /* 通过id查询商品信息
  481. orderInfo(id){
  482. API_
  483. },*/
  484. handleSelectionChange(val) {
  485. this.goodsList = val.map((el) => {
  486. el.product_id = el.id;
  487. el.goods_id = el.id;
  488. return el;
  489. });
  490. },
  491. // 保存已选商品
  492. submitGoosData() {
  493. if (this.goodsList.length >= 1) {
  494. let ids=[]
  495. const param_list={
  496. warehouse_id:this.goodsExchangeAddForm.warehouse_id,
  497. good_ids:ids
  498. }
  499. this.goodsList.forEach(el=>{
  500. ids.push(el.id)
  501. })
  502. API_GoodsExchange.getStockByWarehouseGood(param_list).then(res=>{
  503. res.map(el=>{
  504. el.product_id=el.id
  505. el.goods_id=el.id
  506. })
  507. this.goodsExchangeAddForm.product_list = res;
  508. this.goodsExchangeAddForm.contract_product_list = res;
  509. console.log(res);
  510. this.goodsVisible = false;
  511. })
  512. } else {
  513. this.$message.error("请选择商品信息");
  514. }
  515. },
  516. // 关闭商品明细
  517. closeGoosData() {
  518. this.goodsVisible = false;
  519. },
  520. // 打印功能
  521. printIng() {},
  522. toSearch() {
  523. API_GoodsExchange.getGoodsInfo({
  524. barcode: this.scanGoodsForm.bar_code,
  525. }).then((res) => {
  526. console.log(res);
  527. });
  528. },
  529. // 扫码入库
  530. scanCode() {
  531. this.scanDialogVisible = true;
  532. this.$nextTick(() => {
  533. this.$refs.input.focus();
  534. });
  535. },
  536. /** 获取人员列表 */
  537. GET_AdministratorList() {
  538. API_Auth.getAdministratorList({
  539. page_no: 1,
  540. page_size: 9999,
  541. user_state: 0,
  542. }).then((response) => {
  543. this.adminList = response.data;
  544. });
  545. },
  546. /** 清除已选商品明细 */
  547. cleanGoodsList() {
  548. // 切换部门或仓库需要清除已选对应仓库下的商品数据 change_list
  549. this.goodsExchangeAddForm.contract_product_list = [];
  550. this.goodsExchangeAddForm.product_list = [];
  551. },
  552. changewarehouseList(e) {
  553. this.$set(this.goodsExchangeAddForm, "warehouse_id", "");
  554. this.GET_WarehouseList({ dept_id: e });
  555. this.cleanGoodsList();
  556. },
  557. /** 审核-通过 */
  558. handlePassGoodsExchange() {
  559. if (this.goodsExchangeAddForm.check_amount_same === false) {
  560. this.$confirm(this.goodsExchangeAddForm.diff_amount_message, "提示", {
  561. type: "warning",
  562. })
  563. .then(() => {
  564. this.$confirm("确定通过吗?", "提示", { type: "warning" })
  565. .then(() => {
  566. API_GoodsExchange.auditGoodsExchange(this.id, {
  567. status: "PASS",
  568. }).then(() => {
  569. this.$message.success("已通过!");
  570. const { callback } = this.$route.params;
  571. if (typeof callback === "function") callback();
  572. this.$store.dispatch("delCurrentViews", {
  573. view: this.$route,
  574. $router: this.$router,
  575. });
  576. this.$router.push({ name: "goodsExchange" });
  577. });
  578. })
  579. .catch(() => {});
  580. })
  581. .catch(() => {});
  582. } else {
  583. this.$confirm("确定通过吗?", "提示", { type: "warning" })
  584. .then(() => {
  585. API_GoodsExchange.auditGoodsExchange(this.id, {
  586. status: "PASS",
  587. }).then(() => {
  588. this.$message.success("已通过!");
  589. const { callback } = this.$route.params;
  590. if (typeof callback === "function") callback();
  591. this.$store.dispatch("delCurrentViews", {
  592. view: this.$route,
  593. $router: this.$router,
  594. });
  595. this.$router.push({ name: "goodsExchange" });
  596. });
  597. })
  598. .catch(() => {});
  599. }
  600. },
  601. /** 审核-拒绝 */
  602. handleRejectGoodsExchange() {
  603. this.$confirm("确定拒绝吗?", "提示", { type: "warning" })
  604. .then(() => {
  605. API_GoodsExchange.auditGoodsExchange(this.id, {
  606. status: "REJECT",
  607. reject_reason: this.goodsExchangeAddForm.reject_reason,
  608. }).then(() => {
  609. this.$message.success("已拒绝!");
  610. this.dialogVisible = false;
  611. const { callback } = this.$route.params;
  612. if (typeof callback === "function") callback();
  613. this.$store.dispatch("delCurrentViews", {
  614. view: this.$route,
  615. $router: this.$router,
  616. });
  617. this.$router.push({ name: "goodsExchange" });
  618. });
  619. })
  620. .catch(() => {});
  621. },
  622. /** 获取仓库 */
  623. GET_WarehouseList(e) {
  624. API_BasicSetting.getWarehouseListAll().then((response) => {
  625. this.warehouseList = response;
  626. });
  627. },
  628. //保存
  629. savegoodsExchangeAddForm(){
  630. this.$refs["goodsExchangeAddForm"].validate((valid) => {
  631. if (valid) {
  632. const { id } = this.goodsExchangeAddForm;
  633. const params = this.MixinClone(this.goodsExchangeAddForm);
  634. params.handled_by = this.deptListAll;
  635. API_order.getOrderList({sn:this.goodsExchangeAddForm.sn}).then(res=>{
  636. console.log(res.data);
  637. params.order_id= Number(res.data[0].id)
  638. })
  639. params.staff_name = this.goodsExchangeAddForm.distribution_name;
  640. if (params.warehouse_id) {
  641. params.warehouse_name = this.warehouseList.find(
  642. (ware) => ware.id === params.warehouse_id
  643. ).name;
  644. }
  645. if (params.handled_by_id) {
  646. params.handled_by = this.adminList.find(
  647. (admin) => admin.id === params.handled_by_id
  648. ).real_name;
  649. }
  650. params.change_time = Math.floor(params.change_time / 1000);
  651. //类型
  652. params.save_or_submit="save"
  653. if (!params.contract_product_list.length) {
  654. this.$message.error("请选择商品!");
  655. return;
  656. }
  657. if (this.$route.name === "editInventory") {
  658. API_GoodsExchange.editWarehouseEntry(params).then((response) => {
  659. this.$message.success("修改成功!");
  660. const { callback } = this.$route.params;
  661. if (typeof callback === "function") callback();
  662. this.$store.dispatch("delCurrentViews", {
  663. view: this.$route,
  664. $router: this.$router,
  665. });
  666. this.$router.push({ name: "goodsExchange" });
  667. });
  668. } else if (this.$route.name === "addInventory") {
  669. // 新增入库
  670. API_GoodsExchange.warehouseEntry(params).then(() => {
  671. this.$message.success("添加成功!");
  672. const { callback } = this.$route.params;
  673. if (typeof callback === "function") callback();
  674. this.$store.dispatch("delCurrentViews", {
  675. view: this.$route,
  676. $router: this.$router,
  677. });
  678. this.$router.push({ name: "goodsExchange" });
  679. });
  680. }
  681. }
  682. });
  683. },
  684. //入库
  685. submitgoodsExchangeAddForm() {
  686. this.$refs["goodsExchangeAddForm"].validate((valid) => {
  687. if (valid) {
  688. const { id } = this.goodsExchangeAddForm;
  689. const params = this.MixinClone(this.goodsExchangeAddForm);
  690. params.handled_by = this.deptListAll;
  691. API_order.getOrderList({sn:this.goodsExchangeAddForm.sn}).then(res=>{
  692. console.log(res.data);
  693. params.order_id= Number(res.data[0].id)
  694. })
  695. params.staff_name = this.goodsExchangeAddForm.distribution_name;
  696. if (params.warehouse_id) {
  697. params.warehouse_name = this.warehouseList.find(
  698. (ware) => ware.id === params.warehouse_id
  699. ).name;
  700. }
  701. if (params.handled_by_id) {
  702. params.handled_by = this.adminList.find(
  703. (admin) => admin.id === params.handled_by_id
  704. ).real_name;
  705. }
  706. params.change_time = Math.floor(params.change_time / 1000);
  707. params.save_or_submit="submit"
  708. if (!params.contract_product_list.length) {
  709. this.$message.error("请选择商品!");
  710. return;
  711. }
  712. /* */ if (this.$route.name === "editInventory") {
  713. params.contract_product_list.map(el=>{
  714. el.product_id=el.id
  715. el.goods_id=el.id
  716. })
  717. params.product_list.map(el=>{
  718. el.product_id=el.id
  719. el.goods_id=el.id
  720. })
  721. API_GoodsExchange.editWarehouseEntry(id,params).then((response) => {
  722. this.$message.success("修改成功!");
  723. const { callback } = this.$route.params;
  724. if (typeof callback === "function") callback();
  725. this.$store.dispatch("delCurrentViews", {
  726. view: this.$route,
  727. $router: this.$router,
  728. });
  729. this.$router.push({ name: "goodsExchange" });
  730. });
  731. } else if (this.$route.name === "addInventory") {
  732. // 新增入库
  733. API_GoodsExchange.warehouseEntry(params).then(() => {
  734. this.$message.success("添加成功!");
  735. const { callback } = this.$route.params;
  736. if (typeof callback === "function") callback();
  737. this.$store.dispatch("delCurrentViews", {
  738. view: this.$route,
  739. $router: this.$router,
  740. });
  741. this.$router.push({ name: "goodsExchange" });
  742. });
  743. }
  744. }
  745. });
  746. },
  747. /* returngoodsExchangeAddForm() {
  748. const { id } = this.goodsExchangeAddForm;
  749. const params = this.MixinClone(this.goodsExchangeAddForm);
  750. params.dept_name = this.deptListAll.find(
  751. (dept) => dept.id === params.dept_id
  752. ).name;
  753. params.staff_name = this.goodsExchangeAddForm.distribution_name;
  754. params.warehouse_name = this.warehouseList.find(
  755. (ware) => ware.id === params.warehouse_id
  756. ).name;
  757. params.change_time = Math.floor(params.change_time / 1000);
  758. params.product_list = params.product_list.map((item) => {
  759. //change_list
  760. item.product_sn = item.product_sn;
  761. item.product_name = item.product_name;
  762. item.specification = item.product_specification;
  763. item.product_id = item.product_id;
  764. item.unit = item.unit;
  765. item.stock_sn = item.sn;
  766. item.stock_num = item.remain_num;
  767. item.cost_price = item.product_cost_price;
  768. return item;
  769. });
  770. API_GoodsExchange.returnGoodsExchange(id, params).then(() => {
  771. this.$message.success("换货成功!");
  772. const { callback } = this.$route.params;
  773. if (typeof callback === "function") callback();
  774. this.$store.dispatch("delCurrentViews", {
  775. view: this.$route,
  776. $router: this.$router,
  777. });
  778. this.$router.push({ name: "goodsExchange" });
  779. });
  780. }, */
  781. // 选择出库单
  782. async handleSelectWarehouseEntryBatch() {
  783. if (!this.goodsExchangeAddForm.warehouse_id) {
  784. this.$message.error('请先选择仓库!')
  785. return
  786. }
  787. API_GoodsExchange.getGoodsInfo().then((res) => {
  788. this.goodsData = res.data;
  789. this.goodsVisible = true;
  790. });
  791. /*// if (!this.goodsExchangeAddForm.warehouse_id) {
  792. // this.$message.error('请先选择仓库!')
  793. // return
  794. // }
  795. const goodsData = await this.$EnwarehouseEntryBatch({
  796. goodsApi: "/admin/erp/goods",
  797. warehouseList: this.warehouseList,
  798. //change_list
  799. selectedIds: this.id
  800. ? this.goodsExchangeAddForm.product_list &&
  801. this.goodsExchangeAddForm.product_list.map((item) => item.id)
  802. : this.goodsExchangeAddForm.product_list.map((item) => item.id),
  803. purchasePlanApiParams: {
  804. warehouse_id: this.goodsExchangeAddForm.warehouse_id,
  805. },
  806. });
  807. this.goodsExchangeAddForm.warehouse_id = goodsData.warehouse_id;
  808. this.goodsExchangeAddForm.product_list = goodsData.purchasePlans.map(
  809. (item) => {
  810. //
  811. item.amount = item.entry_price;
  812. item.product_sn = item.product_sn;
  813. item.product_name = item.product_name;
  814. item.specification = item.product_specification;
  815. item.product_id = item.product_id;
  816. item.unit = item.product_unit;
  817. item.stock_sn = item.warehouse_entry_sn;
  818. item.stock_id = item.warehouse_entry_id;
  819. item.stock_batch_sn = item.sn;
  820. item.stock_batch_id = item.id;
  821. item.cost_price = item.product_cost_price;
  822. return item;
  823. }
  824. );
  825. this.goodsExchangeAddForm.change_amount =
  826. this.goodsExchangeAddForm.product_list.reduce(
  827. (sum, obj) => sum + obj.entry_price,
  828. 0
  829. ); */
  830. },
  831. /** 选择订单编号 */
  832. async handleSelectOrderSn() {
  833. const orders = await this.$EnPickerOrder({
  834. orderApi: "admin/erp/order",
  835. selectedIds: [this.goodsExchangeAddForm.order_sn],
  836. limit: 1,
  837. });
  838. this.$set(
  839. this.goodsExchangeAddForm,
  840. "distribution_name",
  841. orders[0].distribution_name
  842. );
  843. const orderIds = orders.map((v) => v.sn);
  844. this.$set(this.goodsExchangeAddForm, "order_sn", orderIds.join(","));
  845. this.GET_WarehouseOutProduct();
  846. },
  847. /** 获取出库单商品明细 */
  848. async GET_WarehouseOutProduct() {
  849. const res = await API_Erp.getWarehouseOutProduct({
  850. order_sn: this.goodsExchangeAddForm.order_sn,
  851. });
  852. this.goodsExchangeAddForm.return_list = res.data.map((item) => {
  853. item.amount = item.product_price;
  854. item.product_sn = item.product_sn;
  855. item.product_name = item.product_name;
  856. item.specification = item.product_specification;
  857. item.product_id = item.product_id;
  858. item.unit = item.product_unit;
  859. item.num = item.return_num;
  860. item.stock_sn = item.warehouse_entry_sn;
  861. item.cost_price = item.product_cost_price;
  862. return item;
  863. });
  864. },
  865. /** 获取部门 */
  866. GET_DeptList() {
  867. API_GoodsExchange.getInfo().then((response) => {
  868. this.deptListAll = response;
  869. this.deptListAll.password = "";
  870. });
  871. },
  872. /** 切换仓库 */
  873. handleChangeWareHouse(val) {
  874. //this.goodsExchangeAddForm.product_list = []change_list
  875. },
  876. /** 获取详情页面数据 */
  877. GET_goodsExchangeAddDetail() {
  878. this.$nextTick(() => {
  879. API_GoodsExchange.getGoodsExchangeInfo(this.id).then((response) => {
  880. this.goodsExchangeAddForm = response;
  881. this.GET_WarehouseList({ dept_id: response.dept_id });
  882. this.goodsExchangeAddForm.change_time = Math.floor(
  883. this.goodsExchangeAddForm.change_time * 1000
  884. );
  885. this.goodsExchangeAddForm.distribution_name = response.staff_name;
  886. this.goodsExchangeAddForm.product_list =
  887. response.product_list.map((item) => {
  888. //change_list
  889. item.name=item.goods_do.name
  890. item.sn=item.goods_do.sn
  891. item.sn_code=item.goods_do.sn_code
  892. item.bar_code=item.goods_do.bar_code
  893. item.entry_price = item.amount;
  894. item.product_specification = item.specification;
  895. item.product_unit = item.unit;
  896. item.warehouse_entry_sn = item.stock_sn;
  897. return item;
  898. });
  899. this.goodsExchangeAddForm.return_list = response.return_list.map(
  900. (item) => {
  901. item.product_price = item.amount;
  902. item.product_specification = item.specification;
  903. item.product_unit = item.unit;
  904. item.return_num = item.num;
  905. item.warehouse_entry_sn = item.stock_sn;
  906. return item;
  907. }
  908. );
  909. // this.GET_WarehouseOutProduct()
  910. });
  911. });
  912. },
  913. },
  914. };
  915. </script>
  916. <style type="text/scss" lang="scss" scoped>
  917. /deep/ {
  918. }
  919. /** 底部步骤 */
  920. .footer {
  921. width: 100%;
  922. padding: 10px;
  923. bottom: 0px;
  924. text-align: center;
  925. z-index: 999;
  926. }
  927. .mx {
  928. display: flex;
  929. align-items: center;
  930. width: 100%;
  931. .button {
  932. margin-left: 10px;
  933. }
  934. }
  935. .change-form {
  936. display: flex;
  937. justify-content: flex-start;
  938. align-items: flex-start;
  939. flex-wrap: wrap;
  940. min-width: 900px;
  941. .change-form-item {
  942. width: 30%;
  943. margin: 0 10px 20px 0;
  944. display: flex;
  945. flex-direction: row;
  946. flex-wrap: nowrap;
  947. }
  948. /deep/ {
  949. .el-form-item__content {
  950. flex: 1;
  951. width: 100%;
  952. }
  953. .el-date-editor,
  954. .el-cascader,
  955. .el-select {
  956. width: 100%;
  957. }
  958. }
  959. }
  960. .bg-in-stock {
  961. background-color: #fff;
  962. margin: 10px;
  963. padding: 25px;
  964. }
  965. .goods-info {
  966. display: flex;
  967. .goods-name-box {
  968. text-align: left;
  969. .goods-name {
  970. text-overflow: ellipsis;
  971. display: -webkit-box;
  972. -webkit-line-clamp: 2;
  973. -webkit-box-orient: vertical;
  974. overflow: hidden;
  975. line-height: 16px;
  976. }
  977. .specs {
  978. color: #999999;
  979. }
  980. }
  981. }
  982. /deep/ {
  983. .el-input--suffix .el-input__inner {
  984. padding-right: 10px;
  985. }
  986. .error-input {
  987. .el-input__inner {
  988. border: 1px solid red;
  989. }
  990. }
  991. }
  992. </style>