SendPurchase.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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 type="primary" link @click="handleRemove($index)"
  136. >删除</el-button
  137. >
  138. </template>
  139. </el-table-column>
  140. </el-table>
  141. </el-form-item>
  142. <el-row>
  143. <el-col :span="4">
  144. <el-form-item label="采购金额" prop="amount">
  145. <el-input
  146. v-model="formData.data.amount"
  147. placeholder="请输入"
  148. disabled
  149. />
  150. </el-form-item>
  151. </el-col>
  152. </el-row>
  153. </el-form>
  154. <el-dialog
  155. v-model="openProduct"
  156. title="选择货品"
  157. width="70%"
  158. append-to-body
  159. >
  160. <SelectGoods
  161. @cancel="openProduct = false"
  162. @pushGoods="pushGoods"
  163. ></SelectGoods>
  164. </el-dialog>
  165. </div>
  166. </template>
  167. <script setup>
  168. import SelectGoods from "@/components/product/SelectGoods";
  169. import { ElMessage, ElMessageBox } from "element-plus";
  170. import useUserStore from "@/store/modules/user";
  171. const route = useRoute();
  172. const { proxy } = getCurrentInstance();
  173. // 接收父组件的传值
  174. const props = defineProps({
  175. queryData: String,
  176. });
  177. let formData = reactive({
  178. data: {
  179. purchaseTime: "",
  180. purchaseDetailList: [],
  181. },
  182. });
  183. let rules = ref({
  184. deptName: [{ required: true, message: "请输入采购部门", trigger: "blur" }],
  185. purchaseName: [
  186. { required: true, message: "请输入采购人名称", trigger: "blur" },
  187. ],
  188. purchaseTime: [
  189. { required: true, message: "请选择采购时间", trigger: "change" },
  190. ],
  191. supplyId: [{ required: true, message: "请选择供应商", trigger: "change" }],
  192. count: [{ required: true, message: "请输入本次采购数量", trigger: "blur" }],
  193. price: [{ required: true, message: "请输入单价", trigger: "blur" }],
  194. remark: [{ required: true, message: "请输入备注", trigger: "blur" }],
  195. });
  196. let openProduct = ref(false);
  197. // 物品相应逻辑
  198. const handleRemove = (index) => {
  199. formData.data.purchaseDetailList.splice(index, 1);
  200. handleChangeAmount();
  201. return ElMessage({
  202. message: "删除成功!",
  203. type: "success",
  204. });
  205. };
  206. const pushGoods = (goods) => {
  207. const arr = goods.map((x) => ({
  208. goodType: x.goodType,
  209. productCode: x.code,
  210. productName: x.name,
  211. productSpec: x.spec,
  212. productUnit: x.unit,
  213. count: 0,
  214. price: 0,
  215. bussinessId: x.id,
  216. amount: 0,
  217. }));
  218. formData.data.purchaseDetailList =
  219. formData.data.purchaseDetailList.concat(arr);
  220. openProduct.value = false;
  221. return ElMessage({
  222. message: "添加成功!",
  223. type: "success",
  224. });
  225. };
  226. // 提交方法
  227. const formDom = ref(null);
  228. const handleSubmit = async () => {
  229. const vaild = await formDom.value.validate();
  230. if (vaild) {
  231. if (formData.data.purchaseDetailList.length > 0) {
  232. const list = formData.data.purchaseDetailList;
  233. for (let i = 0; i < list.length; i++) {
  234. const e = list[i];
  235. if (ids.value.length > 0) {
  236. if (Number(e.subscribeCount) - Number(e.purchaseCount) > 0) {
  237. if (e.count == 0) {
  238. ElMessage({
  239. message: "本次采购数量不能为0!",
  240. type: "info",
  241. });
  242. return false;
  243. }
  244. }
  245. // if (e.count + Number(e.purchaseCount) > Number(e.subscribeCount)) {
  246. // ElMessage({
  247. // message: "本次采购数量和已采购数量和不可大于申购数量!",
  248. // type: "info",
  249. // });
  250. // return false;
  251. // }
  252. } else {
  253. if (e.count == 0) {
  254. ElMessage({
  255. message: "本次采购数量不能为0!",
  256. type: "info",
  257. });
  258. return false;
  259. }
  260. }
  261. }
  262. return true;
  263. }
  264. ElMessage({
  265. message: "请添加采购明细!",
  266. type: "info",
  267. });
  268. return false;
  269. }
  270. return false;
  271. };
  272. // 获取用户信息并赋默认值
  273. const userInfo = useUserStore().user;
  274. onMounted(() => {
  275. formData.data.purchaseTime = proxy.parseTime(new Date());
  276. formData.data.deptName = userInfo.dept.deptName;
  277. formData.data.purchaseName = userInfo.nickName;
  278. getSupplierList();
  279. if (props.queryData.ids) {
  280. ids.value = props.queryData.ids.split(",") || [];
  281. getDetails();
  282. }
  283. });
  284. const ids = ref([]);
  285. const getDetails = () => {
  286. if (props.queryData.type && props.queryData.type === "handoverSlip") {
  287. proxy.post("/contractProduct/getListDetail", ids.value).then((res) => {
  288. formData.data.purchaseDetailList = res.map((x) => {
  289. delete x.id;
  290. return {
  291. ...x,
  292. subscribeCount: x.sumPackQuantity,
  293. purchaseCount: x.sumPurchaseCount,
  294. count: x.expendQuantity || 0,
  295. price: null,
  296. amount: null,
  297. };
  298. });
  299. });
  300. } else {
  301. proxy.post("/subscribeDetail/detail", { ids: ids.value }).then((res) => {
  302. formData.data.purchaseDetailList = res.map((x) => ({
  303. bussinessId: x.bussinessId,
  304. goodType: x.productDefinition,
  305. productCode: x.productCode,
  306. productName: x.productName,
  307. productSpec: x.productSpec,
  308. productUnit: x.productUnit,
  309. purchaseCount: x.purchaseCount,
  310. subscribeCount: x.count,
  311. count: 0,
  312. price: null,
  313. amount: null,
  314. }));
  315. });
  316. }
  317. };
  318. // 获取供应商数据
  319. const supplierData = ref([]);
  320. const getSupplierList = async (req) => {
  321. proxy
  322. .post("/supplierInfo/page", { pageNum: 1, pageSize: 9999 })
  323. .then((res) => {
  324. supplierData.value = res.rows;
  325. });
  326. };
  327. // 供应商改变逻辑
  328. const handleChangeSupplier = (val) => {
  329. console.log(val, "as");
  330. };
  331. // 计算采购总金额
  332. const handleChangeAmount = () => {
  333. let sum = 0;
  334. for (let i = 0; i < formData.data.purchaseDetailList.length; i++) {
  335. const e = formData.data.purchaseDetailList[i];
  336. e.amount = e.count * e.price;
  337. sum += e.amount;
  338. }
  339. formData.data.amount = sum;
  340. };
  341. const productUnit = ref([]);
  342. const getDict = () => {
  343. proxy.getDictOne(["unit"]).then((res) => {
  344. productUnit.value = res["unit"].map((x) => ({
  345. label: x.dictValue,
  346. value: x.dictKey,
  347. }));
  348. });
  349. };
  350. getDict();
  351. watch(
  352. props.queryData,
  353. () => {
  354. if (
  355. props.queryData &&
  356. (route.query.processType == 10 || route.query.processType == 20)
  357. ) {
  358. for (const key in props.queryData) {
  359. formData.data[key] = props.queryData[key];
  360. }
  361. }
  362. },
  363. {
  364. deep: true,
  365. }
  366. );
  367. const judgeStatus = () => {
  368. if (props.queryData.recordList && props.queryData.recordList.length > 0) {
  369. let data = props.queryData.recordList.filter(
  370. (item) => item.status === 2 && item.nodeType !== 1
  371. );
  372. if (data && data.length > 0) {
  373. return true;
  374. }
  375. }
  376. return false;
  377. };
  378. const getFormData = () => {
  379. return formData.data;
  380. };
  381. // 向父组件暴露
  382. defineExpose({
  383. getFormData,
  384. handleSubmit,
  385. });
  386. </script>
  387. <style lang="scss" scoped>
  388. ._t {
  389. margin-bottom: 5px;
  390. font-size: 14px;
  391. }
  392. </style>