addForm.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. <template>
  2. <el-row class="addForm">
  3. <el-col :span="24">
  4. <el-form
  5. :model="ruleForm"
  6. status-icon
  7. :rules="rulesThis"
  8. ref="ruleForm"
  9. :size="'mini'"
  10. label-width="85px"
  11. class="demo-ruleForm"
  12. >
  13. <el-row>
  14. <el-col :span="24" v-if="!desc">
  15. <!-- <div class="label-title-model">出库仓库信息:</div> -->
  16. <!-- !(
  17. id === 'add' ||
  18. (status + '' === '0' && powers.some((i) => i == '005'))
  19. ) -->
  20. <el-form-item label="业务公司" prop="out_companyNo">
  21. <search-work-company
  22. :value="ruleForm.out_companyNo"
  23. :size="'mini'"
  24. :disabled="true"
  25. :is-detail="id !== 'add'"
  26. :placeholder="'业务公司'"
  27. @searchChange="supplierChange($event, 'out_companyNo')"
  28. />
  29. </el-form-item>
  30. <!-- <el-form-item label="公司" prop="supplier_code">
  31. <search-supplier
  32. :value="ruleForm.supplier_code"
  33. :placeholder="'请选择公司'"
  34. :size="'mini'"
  35. :is-detail="id !== 'add'"
  36. :disabled="
  37. !(id === 'add' || (status + '' === '0' && powers.some((i) => i == '005')))
  38. "
  39. :names="supplier_name"
  40. @searchChange="selectSupplierOut"
  41. />
  42. </el-form-item> -->
  43. </el-col>
  44. <el-col :span="12" v-if="!desc">
  45. <el-form-item label="出库仓库" prop="stock_code">
  46. <search-stock
  47. :value="ruleForm.stock_code"
  48. :isDetail="id !== 'add'"
  49. :disabled="
  50. !(
  51. id === 'add' ||
  52. (status + '' === '0' && powers.some((i) => i == '005'))
  53. )
  54. "
  55. :size="'mini'"
  56. :placeholder="'请选择仓库'"
  57. :isRelation="true"
  58. :companyNo="ruleForm.out_companyNo"
  59. :names="''"
  60. @searchChange="selectStockOut"
  61. />
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="12" v-if="!desc">
  65. <!-- <div class="label-title-model">入库仓库信息:</div> -->
  66. <!-- :disabled="
  67. !(
  68. id === 'add' ||
  69. (status + '' === '0' && powers.some((i) => i == '005'))
  70. )
  71. " -->
  72. <!-- <el-form-item label="业务公司" prop="in_companyNo">
  73. <search-work-company
  74. :value="ruleForm.in_companyNo"
  75. :names="''"
  76. :size="'mini'"
  77. :is-detail="id !== 'add'"
  78. disabled
  79. :placeholder="'业务公司'"
  80. @searchChange="supplierChange($event, 'in_companyNo')"
  81. />
  82. </el-form-item> -->
  83. <!-- <el-form-item label="公司" prop="supplier_in_code">
  84. <search-supplier
  85. :value="ruleForm.supplier_in_code"
  86. :placeholder="'请选择公司'"
  87. :size="'mini'"
  88. :is-detail="id !== 'add'"
  89. :disabled="
  90. !(id === 'add' || (status + '' === '0' && powers.some((i) => i == '005')))
  91. "
  92. :names="supplier_in_name"
  93. @searchChange="selectSupplierIn"
  94. />
  95. </el-form-item> -->
  96. <el-form-item label="入库仓库" prop="stock_in_code" v-if="!desc">
  97. <search-stock
  98. :value="ruleForm.stock_in_code"
  99. :isDetail="id !== 'add'"
  100. :noRelation="true"
  101. :size="'mini'"
  102. :disabled="
  103. !(
  104. id === 'add' ||
  105. (status + '' === '0' && powers.some((i) => i == '005'))
  106. )
  107. "
  108. :placeholder="'请选择仓库'"
  109. :isRelation="true"
  110. :companyNo="ruleForm.in_companyNo"
  111. :names="''"
  112. @searchChange="selectStockIn"
  113. />
  114. </el-form-item>
  115. </el-col>
  116. <el-col :span="24" v-if="desc" style="margin-bottom:10px">
  117. <show-data-table
  118. :sitem="sitem"
  119. :columns="cols"
  120. :border="true"
  121. >
  122. <template #in_company="{scope}">
  123. <div style="display:flex;align-items:center">
  124. <el-tooltip :content="'入库方业务公司编码 : ' + sitem.in_code" placement="top">
  125. <i class="el-icon-warning-outline" style="margin-right:2px;cursor:pointer" />
  126. </el-tooltip>
  127. <p>{{sitem.wsm_in_name}}</p>
  128. </div>
  129. </template>
  130. <template #out_company="{scope}">
  131. <div style="display:flex;align-items:center">
  132. <el-tooltip :content="'出库方业务公司编码 : ' + sitem.out_code" placement="top">
  133. <i class="el-icon-warning-outline" style="margin-right:2px;cursor:pointer" />
  134. </el-tooltip>
  135. <p>{{sitem.wsm_out_name}}</p>
  136. </div>
  137. </template>
  138. <template #in_stock="{scope}">
  139. <div style="display:flex;align-items:center">
  140. <el-tooltip :content="'出库仓库编码 : ' + sitem.wsm_out" placement="top">
  141. <i class="el-icon-warning-outline" style="margin-right:2px;cursor:pointer" />
  142. </el-tooltip>
  143. <p>{{sitem.ckc_name}}</p>
  144. </div>
  145. </template>
  146. <template #out_stock="{scope}">
  147. <div style="display:flex;align-items:center">
  148. <el-tooltip :content="'出库仓库编码 : ' + sitem.wsm_in" placement="top">
  149. <i class="el-icon-warning-outline" style="margin-right:2px;cursor:pointer" />
  150. </el-tooltip>
  151. <p>{{sitem.ckr_name}}</p>
  152. </div>
  153. </template>
  154. </show-data-table>
  155. </el-col>
  156. </el-row>
  157. </el-form>
  158. </el-col>
  159. <el-col
  160. :span="24"
  161. v-if="
  162. !(
  163. (status == '3' && powers.some((i) => i == '022')) ||
  164. (status == '4' && powers.some((i) => i == '023'))
  165. )
  166. "
  167. >
  168. <el-form
  169. :model="tableForm"
  170. :rules="tableFormThis"
  171. ref="tableForm"
  172. :size="'mini'"
  173. class="demo-tableForm product_go"
  174. >
  175. <el-table :data="tableForm.product_go" border :size="'mini'" row-key="key">
  176. <template v-for="(item, index) in columns">
  177. <el-table-column
  178. :prop="item.prop"
  179. show-overflow-tooltip
  180. :label="item.label"
  181. v-if="item.type === 'text' && item.show && item.prop !== 'error_code'"
  182. :width="item.width"
  183. :min-width="item.minWidth"
  184. :key="item.prop + index"
  185. />
  186. <el-table-column
  187. :prop="item.prop"
  188. :label="item.label"
  189. v-else-if="item.type === 'text' && item.show && item.prop === 'error_code'"
  190. :width="item.width"
  191. :min-width="item.minWidth"
  192. :key="item.prop + index"
  193. >
  194. <template slot-scope="scope">
  195. <span class="spscope">{{ scope.row.error_msg }}</span>
  196. </template>
  197. </el-table-column>
  198. <el-table-column
  199. :prop="item.prop"
  200. :label="item.label"
  201. v-else-if="item.type !== 'text' && item.show"
  202. :width="item.width"
  203. :min-width="item.minWidth"
  204. :key="item.prop + index"
  205. >
  206. <template slot-scope="scope">
  207. <el-form-item
  208. :prop="'product_go.' + scope.$index + '.' + item.prop"
  209. :rules="scope.row.edit ? tableFormThis[item.prop] : {}"
  210. :size="'mini'"
  211. >
  212. <el-input
  213. v-if="scope.row.edit === true && item.type === 'input'"
  214. :size="'mini'"
  215. maxlength="250"
  216. clearable
  217. v-model="scope.row[item.prop]"
  218. />
  219. <el-select
  220. v-model="scope.row[item.prop]"
  221. v-if="scope.row.edit === true && item.type === 'select'"
  222. style="width: 100%"
  223. clearable
  224. placeholder="异常原因"
  225. @change="elSelectChange($event, scope.$index)"
  226. >
  227. <el-option
  228. v-for="item in options"
  229. :key="item.result_code"
  230. :label="item.result"
  231. :value="item.result_code"
  232. :disabled="item.status + '' === '0'"
  233. >
  234. </el-option>
  235. </el-select>
  236. <span v-if="!scope.row.edit" class="spscope">{{
  237. item.type === "select" ? scope.row.error_msg : scope.row[item.prop]
  238. }}</span>
  239. </el-form-item>
  240. </template>
  241. </el-table-column>
  242. </template>
  243. <el-table-column
  244. fixed="right"
  245. label="操作"
  246. width="80"
  247. v-if="id === 'add' || (status + '' === '0' && powers.some((i) => i == '005'))"
  248. >
  249. <template slot="header" slot-scope="scope">
  250. <span>操作</span>
  251. <el-tooltip
  252. style="margin: 3px 0 0 0"
  253. effect="dark"
  254. class="fr"
  255. content="添加"
  256. placement="top"
  257. >
  258. <i
  259. class="el-icon-circle-plus-outline tb-icon"
  260. style="color: #6954f0; magin: 0 0 0 10px"
  261. @click="openGoodsModel"
  262. ></i>
  263. </el-tooltip>
  264. </template>
  265. <template slot-scope="scope">
  266. <el-tooltip
  267. effect="dark"
  268. content="编辑"
  269. v-if="!scope.row.edit"
  270. placement="top"
  271. >
  272. <i class="el-icon-edit tb-icon" @click="editRow(scope.$index)"></i>
  273. </el-tooltip>
  274. <el-tooltip
  275. effect="dark"
  276. content="保存"
  277. v-if="scope.row.edit"
  278. placement="top"
  279. >
  280. <i
  281. class="el-icon-circle-check tb-icon"
  282. @click="checkRow(scope.$index)"
  283. ></i>
  284. </el-tooltip>
  285. <el-tooltip effect="dark" content="删除" placement="top">
  286. <i
  287. class="el-icon-delete tb-icon"
  288. @click="deleteRow(scope.$index, tableForm.product_go)"
  289. ></i>
  290. </el-tooltip>
  291. </template>
  292. </el-table-column>
  293. </el-table>
  294. </el-form>
  295. </el-col>
  296. <el-col :span="24" style="text-align: right; padding: 10px 0 10px 0">
  297. <el-button
  298. type="primary"
  299. :size="'mini'"
  300. @click="submitForm"
  301. v-if="id === 'add' || (status + '' === '0' && powers.some((i) => i == '005'))"
  302. >保 存
  303. </el-button>
  304. </el-col>
  305. <el-col :span="24">
  306. <search-stock-good-modal
  307. :show-model="showGoodsModel"
  308. :code="stock_code"
  309. @cancel="showGoodsModel = false"
  310. @searchChange="addGoodsRes"
  311. />
  312. </el-col>
  313. </el-row>
  314. </template>
  315. <script>
  316. import asyncRequest from "@/apis/service/stock/allot/detail";
  317. import searchStockGoodModal from "@/components/search-stock-allot-good-modal";
  318. import companyHelper from '@/mixins/companyHelper'
  319. import resToken from "@/mixins/resToken";
  320. import { isnumber } from "@/utils/validate";
  321. import config from "./columns"; //表格列参数
  322. export default {
  323. name: "allot",
  324. props: ["showModel", "id", "sitem", "newTime", "desc"],
  325. mixins: [resToken, companyHelper],
  326. components: { searchStockGoodModal },
  327. computed: {
  328. powers() {
  329. const tran =
  330. this.$store.getters.btnList.find((item) => item.menu_route == "allotDetail") ||
  331. {};
  332. const { action } = tran ?? {};
  333. return action ?? [];
  334. },
  335. },
  336. data() {
  337. return {
  338. showGoodsModel: false,
  339. cols:[
  340. {
  341. prop:'wsm_out_name',
  342. label:'出库方业务公司',
  343. _slot_:"out_company",
  344. span:12
  345. },
  346. {
  347. prop:'ckc_name',
  348. label:'出库方仓库',
  349. _slot_:'in_stock',
  350. span:12
  351. },
  352. {
  353. prop:'wsm_in_name',
  354. label:'入库方业务公司',
  355. _slot_:"in_company",
  356. span:12
  357. },
  358. {
  359. prop:'ckr_name',
  360. label:'入库方仓库',
  361. span:12,
  362. _slot_:'out_stock'
  363. },
  364. ],
  365. status: "",
  366. supplier_code: "",
  367. supplier_name: "",
  368. supplier_in_code: "",
  369. supplier_in_name: "",
  370. stock_code: "",
  371. stock_in_code: "",
  372. loading: false,
  373. showModelThis: this.showModel,
  374. delList: [],
  375. ruleForm: {
  376. supplier_code: [], //出库供应商code
  377. stock_code: [], //出库仓库code
  378. supplier_in_code: [], //入库供应商code
  379. stock_in_code: [], //入库仓库code
  380. in_companyNo: "",
  381. out_companyNo: "",
  382. },
  383. tableForm: {
  384. product_go: [], //出库商品
  385. },
  386. rulesThis: this.rules,
  387. tableFormThis: config.tableFormThis,
  388. rules: {
  389. in_companyNo: [
  390. {
  391. required: true,
  392. message: "请选择入库方业务公司",
  393. trigger: "change",
  394. },
  395. ],
  396. out_companyNo: [
  397. {
  398. required: true,
  399. message: "请选择出库方业务公司",
  400. trigger: "change",
  401. },
  402. ],
  403. supplier_code: [
  404. {
  405. type: "array",
  406. required: true,
  407. message: "请选择供应商",
  408. trigger: "change",
  409. },
  410. ],
  411. stock_code: [
  412. {
  413. type: "array",
  414. required: true,
  415. message: "请选择仓库",
  416. trigger: "change",
  417. },
  418. ],
  419. // supplier_in_code: [
  420. // {
  421. // type: "array",
  422. // required: true,
  423. // message: "请选择供应商",
  424. // trigger: "change",
  425. // },
  426. // ],
  427. stock_in_code: [
  428. {
  429. type: "array",
  430. required: true,
  431. message: "请选择仓库",
  432. trigger: "change",
  433. },
  434. ],
  435. },
  436. columns: [],
  437. tableData: [],
  438. oldList: [],
  439. };
  440. },
  441. watch: {
  442. showModel: function (val) {
  443. this.showModelThis = val;
  444. if (val) {
  445. this.initForm();
  446. }
  447. },
  448. showModelThis(val) {
  449. if (!val) {
  450. this.$emit("cancel");
  451. }
  452. },
  453. newTime: function (val) {
  454. if (val) {
  455. this.initForm();
  456. }
  457. },
  458. },
  459. mounted() {
  460. this.initForm();
  461. },
  462. methods: {
  463. closeModel() {
  464. this.$emit("closeModel");
  465. },
  466. //业务公司选择
  467. async supplierChange(e, key) {
  468. const { code } = e;
  469. this.ruleForm[key] = code || ""; //业务公司编码
  470. this.$refs.ruleForm.validateField(key);
  471. },
  472. openGoodsModel() {
  473. if (this.ruleForm.stock_code.length === 0) {
  474. this.$message.warning("请选择出库仓库!");
  475. return;
  476. }
  477. let index = this.tableForm.product_go.findIndex((v) => v.edit);
  478. if (index !== -1) {
  479. this.$message.warning("当前已有商品正在编辑!");
  480. return;
  481. }
  482. this.showGoodsModel = true;
  483. },
  484. async initForm() {
  485. this.loading = true;
  486. if (this.id === "add") {
  487. this.status = "";
  488. }
  489. this.columns = [];
  490. this.rulesThis = this.rules;
  491. await this.resetForm();
  492. this.loading = false;
  493. },
  494. async resetForm() {
  495. // 重置
  496. await this.$nextTick(() => {
  497. if (this.$refs.ruleForm) {
  498. this.$refs.ruleForm.resetFields();
  499. this.$refs.ruleForm.clearValidate();
  500. const {
  501. wsm_in,
  502. wsm_out,
  503. wsm_in_name,
  504. wsm_out_name,
  505. status,
  506. out_code,
  507. in_code,
  508. in_companyNo,
  509. out_companyNo,
  510. } = this.sitem;
  511. this.status = status || "";
  512. this.supplier_code = out_code || "";
  513. this.supplier_name = wsm_out_name || "";
  514. // this.supplier_in_code = in_code || "";
  515. this.supplier_in_name = wsm_in_name || "";
  516. this.stock_code = wsm_out || "";
  517. this.stock_in_code = wsm_in || "";
  518. this.ruleForm = {
  519. in_companyNo: in_companyNo || "",
  520. out_companyNo: out_companyNo || "",
  521. supplier_code: out_code ? [out_code] : [], //出库供应商code
  522. stock_code: wsm_out ? [wsm_out] : [], //出库仓库code
  523. // supplier_in_code: in_code ? [in_code] : [], //入库供应商code
  524. stock_in_code: wsm_in ? [wsm_in] : [], //入库仓库code
  525. };
  526. if(this.id === 'add') {
  527. this.ruleForm.out_companyNo = this.currentCompany
  528. this.ruleForm.in_companyNo = this.currentCompany
  529. }
  530. // this.ruleForm .out_companyNo =
  531. }
  532. if (this.$refs.tableForm) {
  533. this.$refs.tableForm.resetFields();
  534. this.$refs.tableForm.clearValidate();
  535. const { item, status } = this.sitem;
  536. this.status = status || "";
  537. this.tableForm.product_go = [];
  538. this.delList = [];
  539. let list = JSON.parse(JSON.stringify(item || []));
  540. list.forEach((v) => {
  541. v.usable_num = v.usable_num;
  542. v.type_code = v.good_type_code;
  543. v.error_num = v.error_num || "0";
  544. v.error_code = v.error_code || "";
  545. v.error_msg = v.error_msg || "";
  546. v.error_remark = v.error_remark || "";
  547. v.stock_num = v.stock_num || "0";
  548. v.edit = false;
  549. v.spuCode = v.good_type_code;
  550. this.tableForm.product_go.push(v);
  551. });
  552. let columnsList = JSON.parse(JSON.stringify(config.columns));
  553. columnsList.forEach((v1) => {
  554. if (this.status == "5" || this.status == "4") {
  555. v1.show = true;
  556. }
  557. if (this.status == "4" && v1.prop === "stock_num") {
  558. v1.type = "input";
  559. v1.width = "150px";
  560. }
  561. if (this.status == "3") {
  562. if (v1.prop === "error_remark" || v1.prop === "error_num") {
  563. v1.show = true;
  564. v1.width = "150px";
  565. v1.type = "input";
  566. }
  567. if (v1.prop === "error_code") {
  568. v1.show = true;
  569. v1.width = "150px";
  570. v1.type = "select";
  571. }
  572. }
  573. if (this.status == "0" || this.status == "") {
  574. if (v1.prop === "allot_num") {
  575. v1.width = "150px";
  576. v1.type = "input";
  577. }
  578. }
  579. this.columns.push(v1);
  580. });
  581. this.oldList = list.length === 0 ? [] : JSON.parse(JSON.stringify(list));
  582. }
  583. });
  584. },
  585. async submitForm() {
  586. await this.$refs.ruleForm.validate(async (valid) => {
  587. if (valid) {
  588. if (this.loading) {
  589. return;
  590. }
  591. this.loading = true;
  592. if (this.stock_code == this.stock_in_code) {
  593. this.$message.warning("出入库仓库不能相同!");
  594. this.loading = false;
  595. return;
  596. }
  597. if (this.tableForm.product_go.length === 0) {
  598. this.$message.warning("请选择调拨商品!");
  599. this.loading = false;
  600. return;
  601. }
  602. let index = -1,
  603. isok = true,
  604. ishas = true,
  605. good = [];
  606. this.tableForm.product_go.forEach((v, i) => {
  607. if (v.edit && index === -1) {
  608. index = i;
  609. }
  610. let stock = parseInt(v.usable_num),
  611. num = parseInt(v.allot_num);
  612. if (stock === 0) {
  613. ishas = false;
  614. }
  615. if (num > stock) {
  616. isok = false;
  617. }
  618. });
  619. if (index !== -1) {
  620. this.$message.warning("当前已有商品正在编辑!");
  621. this.loading = false;
  622. return;
  623. }
  624. if (!ishas) {
  625. this.$message.warning("部分商品已无可用库存数,无法进行调拨操作!");
  626. this.loading = false;
  627. return;
  628. }
  629. if (!isok) {
  630. this.$message.warning("部分商品调拨数量已大于可用库存数!");
  631. this.loading = false;
  632. return;
  633. }
  634. good = this.getGoodList();
  635. const { stock_code, stock_in_code } = JSON.parse(JSON.stringify(this.ruleForm));
  636. console.log(good);
  637. const model = {
  638. id: this.id,
  639. wsm_out: stock_code.toString(), //出库仓库
  640. wsm_in: stock_in_code.toString(), //入库仓库
  641. good: good,
  642. };
  643. // this.loading = false;
  644. // return;
  645. let res = {};
  646. if (this.id === "add") {
  647. delete model["id"];
  648. res = await asyncRequest.add(model);
  649. } else {
  650. res = await asyncRequest.update(model);
  651. }
  652. this.loading = false;
  653. if (res && res.code === 0) {
  654. const title = this.id === "add" ? "添加成功" : "修改成功";
  655. this.$notify.success({
  656. title,
  657. message: "",
  658. });
  659. this.$emit("refresh");
  660. } else if (res && res.code >= 100 && res.code <= 104) {
  661. await this.logout();
  662. } else {
  663. this.$message.warning(res.message);
  664. }
  665. } else {
  666. console.log("error submit!!");
  667. return false;
  668. }
  669. });
  670. },
  671. //提交表单前 商品信息list 汇总
  672. getGoodList() {
  673. let newList = JSON.parse(JSON.stringify(this.tableForm.product_go)),
  674. resList = [];
  675. // console.log(this.oldList);
  676. // console.log(this.tableForm.product_go);
  677. if (this.oldList.length === 0) {
  678. resList = JSON.parse(JSON.stringify(newList));
  679. resList.map((v1) => {
  680. console.log(v1);
  681. v1.id = v1.id || "";
  682. v1.is_del = "0";
  683. return v1;
  684. });
  685. } else {
  686. newList.forEach((v1) => {
  687. let index = this.oldList.findIndex((v2) => v1.bnCode === v2.bnCode);
  688. console.log(index);
  689. if (index === -1) {
  690. let model1 = {
  691. bnCode: v1.bnCode || "",
  692. spuCode: v1.spuCode || "",
  693. id: v1.id || "",
  694. allot_num: v1.allot_num || "0",
  695. balance_num: v1.balance_num || "0",
  696. is_del: "0",
  697. };
  698. resList.push(model1);
  699. } else {
  700. let model2 = {
  701. bnCode: v1.bnCode || "",
  702. spuCode: v1.spuCode || "",
  703. id: this.oldList[index].id || "",
  704. allot_num: v1.allot_num || "0",
  705. balance_num: v1.balance_num || "0",
  706. is_del: "0",
  707. };
  708. resList.push(model2);
  709. }
  710. });
  711. }
  712. // (dList = JSON.parse(JSON.stringify(this.delList))), console.log(oldList);
  713. // console.log(oldList);
  714. // oldList.forEach((v1) => {
  715. // let goodModel = {
  716. // bnCode: v1.bnCode || "",
  717. // spuCode: v1.spuCode || "",
  718. // id: v1.id || "",
  719. // // good_code: v1.type_code,
  720. // allot_num: v1.allot_num || "0",
  721. // balance_num: v1.balance_num || "0",
  722. // is_del: "0",
  723. // };
  724. // resList.push(goodModel);
  725. // });
  726. // dList.forEach((v2) => {
  727. // let goodModel = {
  728. // bnCode: v2.bnCode || "",
  729. // spuCode: v2.type_code || "",
  730. // id: v2.id || "",
  731. // allot_num: v2.allot_num,
  732. // balance_num: v2.balance_num || "0",
  733. // is_del: "1",
  734. // };
  735. // resList.push(goodModel);
  736. // });
  737. return resList;
  738. },
  739. // 删除行操作
  740. deleteRow(index, rows) {
  741. if (this.id !== "add" && rows[index].id) {
  742. this.delList.push(rows[index]);
  743. }
  744. rows.splice(index, 1);
  745. },
  746. //保存某一行
  747. checkRow(rowIndex) {
  748. const { usable_num, allot_num } = this.tableForm.product_go[rowIndex];
  749. console.log(usable_num, allot_num);
  750. if (!isnumber(allot_num)) {
  751. this.$message.warning("请输入数字!");
  752. return;
  753. }
  754. if (allot_num === "0") {
  755. this.$message.warning("调拨数量不能为0!");
  756. return;
  757. }
  758. const num = isNaN(parseInt(usable_num)) ? 0 : parseInt(usable_num);
  759. if (parseInt(allot_num) > num) {
  760. this.$message.warning("调拨数量不大于批量库存数!");
  761. return;
  762. }
  763. this.tableForm.product_go[rowIndex].edit = false;
  764. },
  765. //编辑某一行
  766. editRow(rowIndex) {
  767. let index = this.tableForm.product_go.findIndex((v) => v.edit);
  768. if (index !== -1) {
  769. this.$message.warning("请完成其他行的编辑!");
  770. return;
  771. } else {
  772. this.tableForm.product_go[rowIndex].edit = true;
  773. }
  774. },
  775. // 执行点击商品名称的抛出事件
  776. addGoodsRes(e) {
  777. let oldList = JSON.parse(JSON.stringify(this.tableForm.product_go)),
  778. addList = JSON.parse(JSON.stringify(e)),
  779. newList = [].concat(...oldList),
  780. dList = JSON.parse(JSON.stringify(this.delList));
  781. console.log(addList);
  782. addList.forEach((v1, index) => {
  783. let oldindex = oldList.findIndex((v2) => v1.bnCode + "" === v2.bnCode + "");
  784. if (oldindex === -1) {
  785. addList[index].usable_num = addList[index].balance_num;
  786. addList[index].allot_num = addList[index].balance_num;
  787. addList[index].edit = false;
  788. newList.push(addList[index]);
  789. }
  790. });
  791. newList.forEach((v3) => {
  792. let otherindex = dList.findIndex((v4) => v3.bnCode + "" === v4.bnCode + "");
  793. if (otherindex !== -1) {
  794. dList.splice(otherindex, 1);
  795. }
  796. });
  797. this.tableForm.product_go = [].concat(...newList);
  798. this.delList = [].concat(...dList);
  799. this.$refs.tableForm.validateField("product_go");
  800. },
  801. // 选择出库供应商
  802. selectSupplierOut(e) {
  803. const { code } = e;
  804. this.ruleForm.supplier_code = code ? [code] : [];
  805. this.supplier_code = code || "";
  806. this.ruleForm.stock_code = [];
  807. this.tableForm.product_go = [];
  808. this.delList = [];
  809. this.$refs.ruleForm.validateField("supplier_code");
  810. },
  811. // 选择出库仓库
  812. selectStockOut(e) {
  813. if (e && e.id) {
  814. this.ruleForm.stock_code = [e.code];
  815. this.stock_code = e.code;
  816. } else {
  817. this.ruleForm.stock_code = [];
  818. this.stock_code = "";
  819. }
  820. this.tableForm.product_go = [];
  821. this.delList = [];
  822. this.$refs.ruleForm.validateField("stock_code");
  823. },
  824. // 选择入库仓库
  825. selectStockIn(e) {
  826. if (e && e.id) {
  827. this.ruleForm.stock_in_code = [e.code];
  828. this.stock_in_code = e.code;
  829. } else {
  830. this.ruleForm.stock_in_code = [];
  831. this.stock_in_code = "";
  832. }
  833. this.$refs.ruleForm.validateField("stock_in_code");
  834. },
  835. // 选择入库供应商
  836. selectSupplierIn(e) {
  837. if (e && e.id) {
  838. this.ruleForm.supplier_in_code = [e.code];
  839. this.supplier_in_code = e.code;
  840. } else {
  841. this.ruleForm.supplier_in_code = [];
  842. this.supplier_in_code = "";
  843. }
  844. this.ruleForm.stock_in_code = [];
  845. this.$refs.ruleForm.validateField("supplier_in_code");
  846. },
  847. },
  848. };
  849. </script>
  850. <style lang="scss" scoped>
  851. .allot,
  852. .allotDetail {
  853. .label-title-model {
  854. line-height: 30px;
  855. width: 100%;
  856. color: #909399;
  857. font-weight: bold;
  858. font-size: 15px;
  859. padding-bottom: 12px;
  860. text-align: center;
  861. }
  862. .product_go {
  863. .el-form-item--mini.el-form-item {
  864. margin: 0 !important;
  865. .spscope {
  866. word-break: break-all !important;
  867. line-height: 23px !important;
  868. padding: 0 !important;
  869. margin: 0 !important;
  870. list-style: none !important;
  871. font-style: normal !important;
  872. text-decoration: none !important;
  873. border: none !important;
  874. display: inline-block !important;
  875. font-weight: 500 !important;
  876. font-family: "Microsoft Yahei", sans-serif !important;
  877. -webkit-tap-highlight-color: transparent !important;
  878. -webkit-font-smoothing: antialiased !important;
  879. color: #606266 !important;
  880. font-size: 12px !important;
  881. }
  882. }
  883. }
  884. }
  885. </style>