index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <template>
  2. <div class="tenant">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable
  6. :source="sourceList.data"
  7. :pagination="sourceList.pagination"
  8. :config="config"
  9. :loading="loading"
  10. highlight-current-row
  11. :selectConfig="selectConfig"
  12. :table-events="{
  13. //element talbe事件都能传
  14. }"
  15. :action-list="[]"
  16. @get-list="getList"
  17. >
  18. <template #fileSlot="{ item }">
  19. <div
  20. style="cursor: pointer; color: #409eff"
  21. @click="handleClickFile(item)"
  22. >
  23. {{ item.fileName }}
  24. </div>
  25. </template>
  26. </byTable>
  27. </div>
  28. <el-dialog
  29. :title="modalType === 'add' ? '发货登记' : '到货通知'"
  30. v-model="dialogVisible"
  31. width="800"
  32. v-loading="loading"
  33. destroy-on-close
  34. >
  35. <byForm
  36. :formConfig="formConfig"
  37. :formOption="formOption"
  38. v-model="formData.data"
  39. :rules="rules"
  40. ref="byform"
  41. >
  42. <template #detailSlot>
  43. <div style="width: 100%">
  44. <el-table
  45. :data="
  46. modalType === 'add'
  47. ? formData.data.deliverGoodsDetailsList
  48. : formData.data.arrivalDetailList
  49. "
  50. >
  51. <el-table-column
  52. prop="productDefinition"
  53. label="物品类型"
  54. :formatter="
  55. (row) =>
  56. row.productDefinition == 1
  57. ? '产品'
  58. : row.productDefinition == 2
  59. ? '物料'
  60. : ''
  61. "
  62. />
  63. <el-table-column prop="productCode" label="物品编码" />
  64. <el-table-column prop="productName" label="物品名称" />
  65. <el-table-column prop="productSpec" label="规格型号" />
  66. <el-table-column prop="productUnit" label="单位" />
  67. <el-table-column prop="count" label="采购数量" />
  68. <el-table-column
  69. prop="alreadyDeliverGoodsQuantity"
  70. label="累计发货"
  71. v-if="modalType === 'add'"
  72. />
  73. <el-table-column
  74. prop="deliverGoodsQuantity"
  75. label="本次发货"
  76. min-width="150"
  77. v-if="modalType === 'add'"
  78. >
  79. <template #default="{ row, $index }">
  80. <el-form-item
  81. :prop="
  82. 'deliverGoodsDetailsList.' +
  83. $index +
  84. '.deliverGoodsQuantity'
  85. "
  86. :rules="rules.deliverGoodsQuantity"
  87. :inline-message="true"
  88. >
  89. <el-input-number
  90. v-model="row.deliverGoodsQuantity"
  91. :precision="4"
  92. :controls="false"
  93. :min="0"
  94. />
  95. </el-form-item>
  96. </template>
  97. </el-table-column>
  98. <el-table-column
  99. prop="transitQuantity"
  100. label="剩余在途"
  101. v-if="modalType === 'edit'"
  102. />
  103. <el-table-column
  104. prop="deliverGoodsQuantity"
  105. label="本次到货"
  106. v-if="modalType === 'edit'"
  107. />
  108. </el-table>
  109. </div>
  110. </template>
  111. </byForm>
  112. <template #footer>
  113. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  114. <el-button
  115. type="primary"
  116. @click="submitForm()"
  117. size="large"
  118. :loading="submitLoading"
  119. >
  120. 确 定
  121. </el-button>
  122. </template>
  123. </el-dialog>
  124. </div>
  125. </template>
  126. <script setup>
  127. import { ElMessage, ElMessageBox } from "element-plus";
  128. import byTable from "@/components/byTable/index";
  129. import byForm from "@/components/byForm/index";
  130. import { watch } from "vue";
  131. const loading = ref(false);
  132. const submitLoading = ref(false);
  133. const sourceList = ref({
  134. data: [],
  135. pagination: {
  136. total: 3,
  137. pageNum: 1,
  138. pageSize: 10,
  139. },
  140. });
  141. let dialogVisible = ref(false);
  142. let modalType = ref("add");
  143. let rules = ref({
  144. deliverGoodsId: [
  145. { required: true, message: "请选择快递单号", trigger: "change" },
  146. ],
  147. logisticsCompanyCode: [
  148. { required: true, message: "请选择物流公司", trigger: "change" },
  149. ],
  150. code: [{ required: true, message: "请输入物流/快递单号", trigger: "blur" }],
  151. deliverGoodsQuantity: [
  152. { required: true, message: "请输入本次发货", trigger: "blur" },
  153. ],
  154. });
  155. const { proxy } = getCurrentInstance();
  156. const arrivalStatus = [
  157. {
  158. label: "未到货",
  159. value: "0",
  160. },
  161. {
  162. label: "部分到货",
  163. value: "1",
  164. },
  165. {
  166. label: "已到货",
  167. value: "2",
  168. },
  169. ];
  170. const statusData = ref([
  171. {
  172. label: "审批中",
  173. value: "10",
  174. },
  175. {
  176. label: "待采购",
  177. value: "15",
  178. },
  179. {
  180. label: "部分采购",
  181. value: "30",
  182. },
  183. {
  184. label: "已采购",
  185. value: "20",
  186. },
  187. {
  188. label: "已作废",
  189. value: "99",
  190. },
  191. ]);
  192. const selectConfig = reactive([
  193. {
  194. label: "采购状态",
  195. prop: "purchaseStatus",
  196. data: statusData.value,
  197. },
  198. {
  199. label: "到货状态",
  200. prop: "arrivalStatus",
  201. data: arrivalStatus,
  202. },
  203. {
  204. label: "付款状态",
  205. prop: "payStatus",
  206. data: [
  207. {
  208. label: "未付款",
  209. value: "1",
  210. },
  211. {
  212. label: "部分付款",
  213. value: "2",
  214. },
  215. {
  216. label: "已付款",
  217. value: "3",
  218. },
  219. ],
  220. },
  221. ]);
  222. const config = computed(() => {
  223. return [
  224. {
  225. attrs: {
  226. label: "采购单号",
  227. prop: "code",
  228. },
  229. },
  230. {
  231. attrs: {
  232. label: "供应商",
  233. prop: "supplyName",
  234. },
  235. },
  236. {
  237. attrs: {
  238. label: "收货仓库",
  239. prop: "receiptWarehouseName",
  240. },
  241. },
  242. {
  243. attrs: {
  244. label: "采购金额",
  245. prop: "amount",
  246. },
  247. render(amount) {
  248. return proxy.moneyFormat(amount, 2);
  249. },
  250. },
  251. {
  252. attrs: {
  253. label: "采购人",
  254. prop: "purchaseName",
  255. },
  256. },
  257. {
  258. attrs: {
  259. label: "采购时间",
  260. prop: "createTime",
  261. },
  262. },
  263. {
  264. attrs: {
  265. label: "采购状态",
  266. prop: "purchaseStatus",
  267. },
  268. render(status) {
  269. const current = statusData.value.find((x) => x.value == status);
  270. if (current) return current.label;
  271. },
  272. },
  273. {
  274. attrs: {
  275. label: "到货状态",
  276. prop: "arrivalStatus",
  277. },
  278. render(status) {
  279. return arrivalStatus.find((x) => x.value == status).label;
  280. },
  281. },
  282. {
  283. attrs: {
  284. label: "付款状态",
  285. prop: "payStatus1",
  286. },
  287. },
  288. {
  289. attrs: {
  290. label: "操作",
  291. width: "240",
  292. align: "right",
  293. },
  294. renderHTML(row) {
  295. return [
  296. // (row.purchaseStatus == 20 || row.purchaseStatus == 30) &&
  297. // row.arrivalStatus != 2
  298. // ?
  299. {
  300. attrs: {
  301. label: "发货登记",
  302. type: "primary",
  303. text: true,
  304. },
  305. el: "button",
  306. click() {
  307. handleArrival(row, "add");
  308. },
  309. },
  310. {
  311. attrs: {
  312. label: "到货通知",
  313. type: "primary",
  314. text: true,
  315. },
  316. el: "button",
  317. click() {
  318. handleArrival(row, "edit");
  319. },
  320. },
  321. {
  322. attrs: {
  323. label: "作废",
  324. type: "primary",
  325. text: true,
  326. },
  327. el: "button",
  328. click() {
  329. handleEdit(row, 88);
  330. },
  331. },
  332. {
  333. attrs: {
  334. label: "终止",
  335. type: "primary",
  336. text: true,
  337. },
  338. el: "button",
  339. click() {
  340. handleEdit(row, 99);
  341. },
  342. },
  343. ];
  344. },
  345. },
  346. ];
  347. });
  348. let formData = reactive({
  349. data: {},
  350. });
  351. const formOption = reactive({
  352. inline: true,
  353. labelWidth: 100,
  354. itemWidth: 100,
  355. });
  356. const byform = ref(null);
  357. let formConfig = reactive([]);
  358. const configData = [
  359. [
  360. {
  361. type: "title",
  362. title: "基础信息",
  363. },
  364. {
  365. type: "input",
  366. prop: "supplyName",
  367. label: "供应商",
  368. disabled: true,
  369. itemWidth: 50,
  370. },
  371. {
  372. type: "input",
  373. prop: "purchaseCode",
  374. label: "采购单号",
  375. disabled: true,
  376. itemWidth: 50,
  377. },
  378. {
  379. type: "select",
  380. label: "物流信息",
  381. prop: "logisticsCompanyCode",
  382. itemWidth: 50,
  383. style: {
  384. width: "100%",
  385. },
  386. },
  387. {
  388. type: "input",
  389. label: " ",
  390. prop: "code",
  391. placeholder: "物流/快递单号",
  392. itemWidth: 50,
  393. },
  394. {
  395. type: "title",
  396. title: "发货明细",
  397. },
  398. {
  399. type: "slot",
  400. slotName: "detailSlot",
  401. label: "",
  402. },
  403. ],
  404. [
  405. {
  406. type: "title",
  407. title: "基础信息",
  408. },
  409. {
  410. type: "input",
  411. prop: "supplyName",
  412. label: "供应商",
  413. disabled: true,
  414. itemWidth: 50,
  415. },
  416. {
  417. type: "input",
  418. prop: "purchaseCode",
  419. label: "采购单号",
  420. disabled: true,
  421. itemWidth: 50,
  422. },
  423. {
  424. type: "select",
  425. label: "物流/快递单号",
  426. prop: "deliverGoodsId",
  427. itemWidth: 50,
  428. style: {
  429. width: "100%",
  430. },
  431. },
  432. {
  433. type: "title",
  434. title: "发货明细",
  435. },
  436. {
  437. type: "slot",
  438. slotName: "detailSlot",
  439. label: "",
  440. },
  441. ],
  442. ];
  443. const deliverData = ref([]);
  444. const getList = async (req) => {
  445. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  446. loading.value = true;
  447. proxy
  448. .post("/purchase/pageByWdly", sourceList.value.pagination)
  449. .then((message) => {
  450. console.log(message);
  451. sourceList.value.data = message.rows.map((x) => ({
  452. ...x,
  453. ...JSON.parse(x.victoriatouristJson),
  454. }));
  455. sourceList.value.pagination.total = message.total;
  456. setTimeout(() => {
  457. loading.value = false;
  458. }, 200);
  459. });
  460. };
  461. const submitForm = () => {
  462. byform.value.handleSubmit((valid) => {
  463. if (modalType.value === "add") {
  464. const list = formData.data.deliverGoodsDetailsList;
  465. const total = list.reduce(
  466. (total, x) => (total += Number(x.deliverGoodsQuantity)),
  467. 0
  468. );
  469. if (!(total > 0)) {
  470. return ElMessage({
  471. message: `本次发货不能为0!`,
  472. type: "info",
  473. });
  474. }
  475. for (let i = 0; i < list.length; i++) {
  476. const e = list[i];
  477. if (
  478. Number(e.alreadyDeliverGoodsQuantity) +
  479. Number(e.deliverGoodsQuantity) >
  480. Number(e.count)
  481. ) {
  482. return ElMessage({
  483. message: `本次发货加累计发货不可大于采购数量!`,
  484. type: "info",
  485. });
  486. }
  487. }
  488. loading.value = true;
  489. formData.data.deliverGoodsDetailsList = list.map((x) => ({
  490. purchaseDetailId: x.purchaseDetailId,
  491. deliverGoodsQuantity: x.deliverGoodsQuantity,
  492. }));
  493. proxy.post("/deliverGoods/add", formData.data).then((res) => {
  494. ElMessage({
  495. message: `操作成功!`,
  496. type: "success",
  497. });
  498. dialogVisible.value = false;
  499. loading.value = false;
  500. getList();
  501. });
  502. } else if (modalType.value === "edit") {
  503. loading.value = true;
  504. formData.data.arrivalDetailList = formData.data.arrivalDetailList.map(
  505. (x) => ({
  506. bussinessId: x.bussinessId,
  507. purchaseDetailId: x.purchaseDetailId,
  508. deliverGoodsDetailsId: x.deliverGoodsDetailsId,
  509. count: x.deliverGoodsQuantity,
  510. })
  511. );
  512. const victoriatouristJson = {
  513. deliverGoodsId: formData.data.deliverGoodsId,
  514. logisticsCompanyCode: formData.data.logisticsCompanyCode,
  515. code: formData.data.code,
  516. };
  517. formData.data.victoriatouristJson = JSON.stringify(victoriatouristJson);
  518. proxy.post("/arrival/addByWdly", formData.data).then((res) => {
  519. ElMessage({
  520. message: `操作成功!`,
  521. type: "success",
  522. });
  523. dialogVisible.value = false;
  524. loading.value = false;
  525. getList();
  526. });
  527. }
  528. });
  529. };
  530. const getDtl = (row) => {
  531. modalType.value = "edit";
  532. proxy.post("/productionProcesses/detail", { id: row.id }).then((res) => {
  533. formData.data = res;
  534. dialogVisible.value = true;
  535. });
  536. };
  537. const handleEdit = (row, status) => {
  538. let purchaseStatusName = status == 88 ? "作废" : "终止";
  539. const data = { ...row, purchaseStatus: status };
  540. // 弹窗提示是否删除
  541. ElMessageBox.confirm(
  542. `此操作将${purchaseStatusName}该数据, 是否继续?`,
  543. "提示",
  544. {
  545. confirmButtonText: "确定",
  546. cancelButtonText: "取消",
  547. type: "warning",
  548. }
  549. ).then(() => {
  550. // 删除
  551. proxy.post("/purchase/edit", data).then((res) => {
  552. ElMessage({
  553. message: `${purchaseStatusName}成功`,
  554. type: "success",
  555. });
  556. getList();
  557. });
  558. });
  559. };
  560. // 获取供应商数据
  561. const supplierData = ref([]);
  562. const getSupplierList = async (req) => {
  563. proxy
  564. .post("/supplierInfo/page", { pageNum: 1, pageSize: 9999 })
  565. .then((res) => {
  566. supplierData.value = res.rows;
  567. });
  568. };
  569. const logisticsData = ref([]);
  570. const getLogisticsData = (row) => {
  571. proxy.post("/companyInfo/list", { pageNum: 1, pageSize: 999 }).then((res) => {
  572. logisticsData.value = res.reverse().slice(0, 100); //截取前100
  573. });
  574. };
  575. const handleArrival = (row, type) => {
  576. modalType.value = type;
  577. if (type === "add") {
  578. formConfig = configData[0];
  579. formConfig[3].data = logisticsData.value.map((x) => ({
  580. label: x.name,
  581. value: x.code,
  582. }));
  583. proxy.post("/deliverGoodsDetails/detail", { id: row.id }).then((res) => {
  584. formData.data = {
  585. purchaseId: row.id,
  586. supplyName: row.supplyName,
  587. purchaseCode: row.code,
  588. supplyId: res.supplyId,
  589. code: "",
  590. logisticsCompanyCode: "",
  591. deliverGoodsDetailsList: res.map((x) => ({
  592. ...x,
  593. purchaseDetailId: x.id,
  594. alreadyDeliverGoodsQuantity: x.deliverGoodsQuantity,
  595. deliverGoodsQuantity: 0,
  596. })),
  597. };
  598. dialogVisible.value = true;
  599. });
  600. } else if (type === "edit") {
  601. formConfig = configData[1];
  602. proxy.post("/deliverGoods/list", { id: row.id }).then((res) => {
  603. deliverData.value = res;
  604. formConfig[3].data = res.map((x) => ({
  605. ...x,
  606. label: x.code,
  607. value: x.id,
  608. }));
  609. formData.data = {
  610. purchaseId: row.id,
  611. supplyName: row.supplyName,
  612. purchaseCode: row.code,
  613. supplyId: row.supplyId,
  614. code: "",
  615. logisticsCompanyCode: "",
  616. deliverGoodsId: "",
  617. arrivalDetailList: [],
  618. };
  619. dialogVisible.value = true;
  620. });
  621. }
  622. };
  623. watch(
  624. () => formData.data.deliverGoodsId,
  625. (val) => {
  626. if (val) {
  627. const current = deliverData.value.find((x) => x.id === val);
  628. formData.data.logisticsCompanyCode = current
  629. ? current.logisticsCompanyCode
  630. : "";
  631. formData.data.code = current ? current.code : "";
  632. // formData.data.logisticsCompanyName = current ? current.logisticsCompanyCode : "";
  633. proxy.post("/deliverGoods/detail", { id: val }).then((res) => {
  634. formData.data.arrivalDetailList = res.map((x) => ({
  635. count: x.count,
  636. productName: x.name,
  637. productSpec: x.spec,
  638. productUnit: x.unit,
  639. productType: x.type,
  640. productCode: x.code,
  641. bussinessId: x.productId,
  642. purchaseDetailId: x.purchaseDetailId,
  643. deliverGoodsDetailsId: x.deliverGoodsId,
  644. transitQuantity: x.transitQuantity,
  645. deliverGoodsQuantity: x.deliverGoodsQuantity,
  646. productDefinition: x.definition,
  647. }));
  648. });
  649. }
  650. }
  651. );
  652. getList();
  653. getLogisticsData();
  654. </script>
  655. <style lang="scss" scoped>
  656. .tenant {
  657. padding: 20px;
  658. }
  659. </style>