goodsExchangeAdd.vue 36 KB

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