SendPurchase.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <template>
  2. <div style="width: 100%; padding: 0px 15px">
  3. <el-form
  4. :model="formData.data"
  5. :rules="rules"
  6. ref="formDom"
  7. label-position="top"
  8. :disabled="judgeStatus()"
  9. >
  10. <div class="_t">基础信息</div>
  11. <el-row :gutter="10">
  12. <el-col :span="6">
  13. <el-form-item label="采购部门" prop="deptName">
  14. <el-input v-model="formData.data.deptName" placeholder="请输入">
  15. </el-input>
  16. </el-form-item>
  17. </el-col>
  18. <el-col :span="6">
  19. <el-form-item label="采购人" prop="purchaseName">
  20. <el-input v-model="formData.data.purchaseName" placeholder="请输入">
  21. </el-input>
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="6">
  25. <el-form-item label="采购时间" prop="purchaseTime">
  26. <el-date-picker
  27. v-model="formData.data.purchaseTime"
  28. type="datetime"
  29. placeholder="请选择"
  30. />
  31. </el-form-item>
  32. </el-col>
  33. </el-row>
  34. <el-row :gutter="10">
  35. <el-col :span="8">
  36. <el-form-item label="供应商" prop="supplyId">
  37. <el-select
  38. v-model="formData.data.supplyId"
  39. placeholder="请选择"
  40. @change="handleChangeSupplier"
  41. filterable
  42. style="width: 100%"
  43. >
  44. <el-option
  45. v-for="item in supplierData"
  46. :label="item.name"
  47. :value="item.id"
  48. >
  49. </el-option>
  50. </el-select>
  51. </el-form-item>
  52. </el-col>
  53. </el-row>
  54. <el-form-item label="采购说明" prop="purchaseContent">
  55. <el-input
  56. v-model="formData.data.purchaseContent"
  57. placeholder="请输入"
  58. type="textarea"
  59. >
  60. </el-input>
  61. </el-form-item>
  62. <div class="_t">采购明细</div>
  63. <el-form-item>
  64. <el-button
  65. type="primary"
  66. @click="openProduct = true"
  67. style="margin: 10px 0"
  68. v-if="ids.length == 0"
  69. >
  70. 添加货品
  71. </el-button>
  72. <el-table :data="formData.data.purchaseDetailList">
  73. <el-table-column
  74. prop="goodType"
  75. label="货品类型"
  76. :formatter="(row) => (row.goodType == 1 ? '产品' : '物料')"
  77. />
  78. <el-table-column prop="productCode" label="货品编码" />
  79. <el-table-column prop="productName" label="货品名称" />
  80. <el-table-column prop="productSpec" label="规格型号" />
  81. <el-table-column
  82. prop="productUnit"
  83. label="单位"
  84. :formatter="(row) => dictValueLabel(row.productUnit, productUnit)"
  85. />
  86. <el-table-column
  87. prop="subscribeCount"
  88. label="申购数量"
  89. v-if="ids.length > 0"
  90. />
  91. <el-table-column
  92. prop="purchaseCount"
  93. label="已采购数量"
  94. v-if="ids.length > 0"
  95. />
  96. <el-table-column prop="count" label="本次采购" min-width="150">
  97. <template #default="{ row, $index }">
  98. <el-form-item
  99. :prop="'purchaseDetailList.' + $index + '.count'"
  100. :rules="rules.count"
  101. :inline-message="true"
  102. >
  103. <el-input-number
  104. onmousewheel="return false;"
  105. v-model="row.count"
  106. :precision="4"
  107. :controls="false"
  108. :min="0"
  109. @change="handleChangeAmount"
  110. />
  111. </el-form-item>
  112. </template>
  113. </el-table-column>
  114. <el-table-column prop="price" label="单价" min-width="150">
  115. <template #default="{ row, $index }">
  116. <el-form-item
  117. :prop="'purchaseDetailList.' + $index + '.price'"
  118. :rules="rules.price"
  119. :inline-message="true"
  120. >
  121. <el-input-number
  122. onmousewheel="return false;"
  123. v-model="row.price"
  124. :precision="4"
  125. :controls="false"
  126. :min="0"
  127. @change="handleChangeAmount"
  128. />
  129. </el-form-item>
  130. </template>
  131. </el-table-column>
  132. <el-table-column prop="amount" label="金额" />
  133. <el-table-column prop="zip" label="操作" width="100">
  134. <template #default="{ $index }">
  135. <el-button
  136. type="primary"
  137. link
  138. @click="handleRemove($index, 20)"
  139. :disabled="formData.data.purchaseDetailList.length === 1"
  140. >删除</el-button
  141. >
  142. </template>
  143. </el-table-column>
  144. </el-table>
  145. </el-form-item>
  146. <el-row>
  147. <el-col :span="4">
  148. <el-form-item label="商品金额小计" prop="productAmount">
  149. <el-input
  150. v-model="formData.data.productAmount"
  151. placeholder="请输入"
  152. disabled
  153. />
  154. </el-form-item>
  155. </el-col>
  156. </el-row>
  157. <div class="_t">其他收费项目</div>
  158. <el-form-item>
  159. <el-button type="primary" style="margin: 10px 0" @click="handleAdd">
  160. 添加
  161. </el-button>
  162. <el-table :data="formData.data.otherFeeList">
  163. <el-table-column prop="name" label="收费项目" min-width="150">
  164. <template #default="{ row, $index }">
  165. <el-form-item
  166. :prop="'otherFeeList.' + $index + '.name'"
  167. :rules="rulesOne.name"
  168. :inline-message="true"
  169. >
  170. <el-autocomplete
  171. v-model="row.name"
  172. :fetch-suggestions="querySearchPerson"
  173. clearable
  174. class="inline-input w-50"
  175. placeholder="请输入"
  176. @select="(val) => handlePerson(val, $index)"
  177. >
  178. </el-autocomplete>
  179. </el-form-item>
  180. </template>
  181. </el-table-column>
  182. <el-table-column prop="price" label="金额" min-width="150">
  183. <template #default="{ row, $index }">
  184. <el-form-item
  185. :prop="'otherFeeList.' + $index + '.price'"
  186. :rules="rulesOne.price"
  187. :inline-message="true"
  188. >
  189. <el-input-number
  190. v-model="row.price"
  191. :precision="4"
  192. :controls="false"
  193. @change="handleChangeAmount"
  194. />
  195. </el-form-item>
  196. </template>
  197. </el-table-column>
  198. <el-table-column prop="remark" label="备注" min-width="150">
  199. <template #default="{ row, $index }">
  200. <el-form-item
  201. :prop="'otherFeeList.' + $index + '.remark'"
  202. :inline-message="true"
  203. >
  204. <el-input v-model="row.remark" placeholder="请输入" />
  205. </el-form-item>
  206. </template>
  207. </el-table-column>
  208. <el-table-column prop="zip" label="操作" width="100">
  209. <template #default="{ $index }">
  210. <el-button type="primary" link @click="handleRemove($index, 10)"
  211. >删除</el-button
  212. >
  213. </template>
  214. </el-table-column>
  215. </el-table>
  216. </el-form-item>
  217. <el-row>
  218. <el-col :span="4">
  219. <el-form-item label="其他收费小计" prop="otherAmount">
  220. <el-input
  221. v-model="formData.data.otherAmount"
  222. placeholder="请输入"
  223. disabled
  224. />
  225. </el-form-item>
  226. </el-col>
  227. </el-row>
  228. <!-- <div class="_t">采购总金额</div> -->
  229. <el-row>
  230. <el-col :span="4">
  231. <el-form-item label="采购总金额" prop="amount">
  232. <el-input
  233. v-model="formData.data.amount"
  234. placeholder="请输入"
  235. disabled
  236. />
  237. </el-form-item>
  238. </el-col>
  239. </el-row>
  240. </el-form>
  241. <el-dialog
  242. v-model="openProduct"
  243. title="选择货品"
  244. width="70%"
  245. append-to-body
  246. >
  247. <SelectGoods
  248. @cancel="openProduct = false"
  249. @pushGoods="pushGoods"
  250. ></SelectGoods>
  251. </el-dialog>
  252. </div>
  253. </template>
  254. <script setup>
  255. import SelectGoods from "@/components/product/SelectGoods";
  256. import { ElMessage, ElMessageBox } from "element-plus";
  257. import useUserStore from "@/store/modules/user";
  258. const route = useRoute();
  259. const { proxy } = getCurrentInstance();
  260. // 接收父组件的传值
  261. const props = defineProps({
  262. queryData: String,
  263. });
  264. let formData = reactive({
  265. data: {
  266. purchaseTime: "",
  267. purchaseDetailList: [],
  268. otherFeeList: [],
  269. },
  270. });
  271. let rules = ref({
  272. deptName: [{ required: true, message: "请输入采购部门", trigger: "blur" }],
  273. purchaseName: [
  274. { required: true, message: "请输入采购人名称", trigger: "blur" },
  275. ],
  276. purchaseTime: [
  277. { required: true, message: "请选择采购时间", trigger: "change" },
  278. ],
  279. supplyId: [{ required: true, message: "请选择供应商", trigger: "change" }],
  280. count: [{ required: true, message: "请输入本次采购数量", trigger: "blur" }],
  281. price: [{ required: true, message: "请输入单价", trigger: "blur" }],
  282. remark: [{ required: true, message: "请输入备注", trigger: "blur" }],
  283. });
  284. let rulesOne = ref({
  285. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  286. price: [{ required: true, message: "请输入金额", trigger: "blur" }],
  287. });
  288. let openProduct = ref(false);
  289. // 物品相应逻辑
  290. const handleRemove = (index, type) => {
  291. if (type === 20) {
  292. formData.data.purchaseDetailList.splice(index, 1);
  293. return ElMessage({
  294. message: "删除成功!",
  295. type: "success",
  296. });
  297. } else {
  298. formData.data.otherFeeList.splice(index, 1);
  299. }
  300. handleChangeAmount();
  301. };
  302. const handleAdd = () => {
  303. formData.data.otherFeeList.push({
  304. name: "",
  305. price: undefined,
  306. remark: "",
  307. });
  308. };
  309. const pushGoods = (goods) => {
  310. const arr = goods.map((x) => ({
  311. goodType: x.goodType,
  312. productCode: x.code,
  313. productName: x.name,
  314. productSpec: x.spec,
  315. productUnit: x.unit,
  316. count: 0,
  317. price: 0,
  318. bussinessId: x.id,
  319. amount: 0,
  320. }));
  321. formData.data.purchaseDetailList =
  322. formData.data.purchaseDetailList.concat(arr);
  323. openProduct.value = false;
  324. return ElMessage({
  325. message: "添加成功!",
  326. type: "success",
  327. });
  328. };
  329. // 提交方法
  330. const formDom = ref(null);
  331. const handleSubmit = async () => {
  332. const vaild = await formDom.value.validate();
  333. if (vaild) {
  334. if (formData.data.purchaseDetailList.length > 0) {
  335. const list = formData.data.purchaseDetailList;
  336. for (let i = 0; i < list.length; i++) {
  337. const e = list[i];
  338. if (ids.value.length > 0) {
  339. if (Number(e.subscribeCount) - Number(e.purchaseCount) > 0) {
  340. if (e.count == 0) {
  341. ElMessage({
  342. message: "本次采购数量不能为0!",
  343. type: "info",
  344. });
  345. return false;
  346. }
  347. }
  348. // if (e.count + Number(e.purchaseCount) > Number(e.subscribeCount)) {
  349. // ElMessage({
  350. // message: "本次采购数量和已采购数量和不可大于申购数量!",
  351. // type: "info",
  352. // });
  353. // return false;
  354. // }
  355. } else {
  356. if (e.count == 0) {
  357. ElMessage({
  358. message: "本次采购数量不能为0!",
  359. type: "info",
  360. });
  361. return false;
  362. }
  363. }
  364. }
  365. return true;
  366. }
  367. ElMessage({
  368. message: "请添加采购明细!",
  369. type: "info",
  370. });
  371. return false;
  372. }
  373. return false;
  374. };
  375. // 获取用户信息并赋默认值
  376. const userInfo = useUserStore().user;
  377. onMounted(() => {
  378. formData.data.purchaseTime = proxy.parseTime(new Date());
  379. formData.data.deptName = userInfo.dept.deptName;
  380. formData.data.purchaseName = userInfo.nickName;
  381. getSupplierList();
  382. if (props.queryData.ids) {
  383. ids.value = props.queryData.ids.split(",") || [];
  384. getDetails();
  385. }
  386. });
  387. const ids = ref([]);
  388. const getDetails = () => {
  389. if (props.queryData.type && props.queryData.type === "handoverSlip") {
  390. proxy.post("/contractProduct/getListDetail", ids.value).then((res) => {
  391. formData.data.purchaseDetailList = res.map((x) => {
  392. delete x.id;
  393. return {
  394. ...x,
  395. subscribeCount: x.sumPackQuantity,
  396. purchaseCount: x.sumPurchaseCount || 0,
  397. count: x.expendQuantity || 0,
  398. price: null,
  399. amount: null,
  400. };
  401. });
  402. });
  403. } else {
  404. proxy.post("/subscribeDetail/detail", { ids: ids.value }).then((res) => {
  405. formData.data.purchaseDetailList = res.map((x) => ({
  406. bussinessId: x.bussinessId,
  407. goodType: x.productDefinition,
  408. productCode: x.productCode,
  409. productName: x.productName,
  410. productSpec: x.productSpec,
  411. productUnit: x.productUnit,
  412. purchaseCount: x.purchaseCount,
  413. subscribeCount: x.count,
  414. count: 0,
  415. price: null,
  416. amount: null,
  417. }));
  418. });
  419. }
  420. };
  421. // 获取供应商数据
  422. const supplierData = ref([]);
  423. const otherFeeListData = ref([]);
  424. const getSupplierList = async (req) => {
  425. proxy
  426. .post("/supplierInfo/page", { pageNum: 1, pageSize: 9999 })
  427. .then((res) => {
  428. supplierData.value = res.rows;
  429. });
  430. };
  431. // 供应商改变逻辑
  432. const handleChangeSupplier = (val) => {
  433. const ids = formData.data.purchaseDetailList.map((x) => x.bussinessId);
  434. proxy
  435. .post("/supplierPrice/getSupplierPriceByProductIds", {
  436. supplierInfoId: val,
  437. productIdList: ids,
  438. })
  439. .then((res) => {
  440. if (res && Object.keys(res).length > 0) {
  441. for (let i = 0; i < formData.data.purchaseDetailList.length; i++) {
  442. const e = formData.data.purchaseDetailList[i];
  443. for (const key in res) {
  444. if (e.bussinessId === key) {
  445. e.price = Number(res[key]);
  446. }
  447. }
  448. }
  449. } else {
  450. for (let i = 0; i < formData.data.purchaseDetailList.length; i++) {
  451. const e = formData.data.purchaseDetailList[i];
  452. e.price = 0;
  453. }
  454. }
  455. handleChangeAmount();
  456. });
  457. };
  458. const handleChangeProductAmount = () => {
  459. let sum = 0;
  460. for (let i = 0; i < formData.data.purchaseDetailList.length; i++) {
  461. const e = formData.data.purchaseDetailList[i];
  462. e.amount = parseFloat(e.count * e.price).toFixed(4);
  463. sum += Number(e.amount);
  464. }
  465. formData.data.productAmount = parseFloat(sum).toFixed(4);
  466. };
  467. const handleChangeOtherAmount = () => {
  468. let sum = 0;
  469. for (let i = 0; i < formData.data.otherFeeList.length; i++) {
  470. const e = formData.data.otherFeeList[i];
  471. sum += Number(e.price);
  472. }
  473. formData.data.otherAmount = parseFloat(sum).toFixed(4);
  474. };
  475. // 计算采购总金额
  476. const handleChangeAmount = () => {
  477. handleChangeProductAmount();
  478. handleChangeOtherAmount();
  479. let sum = 0;
  480. for (let i = 0; i < formData.data.purchaseDetailList.length; i++) {
  481. const e = formData.data.purchaseDetailList[i];
  482. e.amount = parseFloat(e.count * e.price).toFixed(4);
  483. sum += Number(e.amount);
  484. }
  485. for (let i = 0; i < formData.data.otherFeeList.length; i++) {
  486. const e = formData.data.otherFeeList[i];
  487. sum += Number(e.price);
  488. }
  489. formData.data.amount = parseFloat(sum).toFixed(4);
  490. };
  491. const productUnit = ref([]);
  492. const getDict = () => {
  493. proxy.getDictOne(["unit"]).then((res) => {
  494. productUnit.value = res["unit"].map((x) => ({
  495. label: x.dictValue,
  496. value: x.dictKey,
  497. }));
  498. });
  499. proxy.get("/purchaseOtherFee/listName").then((res) => {
  500. otherFeeListData.value = res.data.map((x) => ({ ...x, value: x.name }));
  501. });
  502. };
  503. getDict();
  504. const createFilter = (queryString) => {
  505. return (restaurant) => {
  506. return (
  507. restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
  508. );
  509. };
  510. };
  511. const querySearchPerson = (queryString, callback) => {
  512. const results = queryString
  513. ? otherFeeListData.value.filter(createFilter(queryString))
  514. : otherFeeListData.value;
  515. callback(results);
  516. };
  517. const handlePerson = (item, index) => {
  518. formData.data.otherFeeList[index].name = item.name;
  519. formData.data.otherFeeList[index].price = item.price ? item.price : 0;
  520. formData.data.otherFeeList[index].remark = item.remark ? item.remark : "";
  521. };
  522. watch(
  523. props.queryData,
  524. () => {
  525. if (
  526. props.queryData &&
  527. (route.query.processType == 10 || route.query.processType == 20)
  528. ) {
  529. for (const key in props.queryData) {
  530. formData.data[key] = props.queryData[key];
  531. }
  532. }
  533. },
  534. {
  535. deep: true,
  536. }
  537. );
  538. const judgeStatus = () => {
  539. if (props.queryData.recordList && props.queryData.recordList.length > 0) {
  540. let data = props.queryData.recordList.filter(
  541. (item) => item.status === 2 && item.nodeType !== 1
  542. );
  543. if (data && data.length > 0) {
  544. return true;
  545. }
  546. }
  547. return false;
  548. };
  549. const getFormData = () => {
  550. return formData.data;
  551. };
  552. // 向父组件暴露
  553. defineExpose({
  554. getFormData,
  555. handleSubmit,
  556. });
  557. </script>
  558. <style lang="scss" scoped>
  559. ._t {
  560. margin-bottom: 5px;
  561. font-size: 14px;
  562. }
  563. </style>