index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. select: select,
  15. }"
  16. :action-list="[
  17. {
  18. text: '产品分拆',
  19. action: () => openModal('add'),
  20. },
  21. ]"
  22. @get-list="getList"
  23. >
  24. <template #slotName="{ item }">
  25. {{ item.createTime }}
  26. </template>
  27. </byTable>
  28. </div>
  29. <el-dialog
  30. :title="modalType == 'add' ? '产品分拆' : '分拆详情'"
  31. v-model="dialogVisible"
  32. width="800"
  33. v-loading="loading"
  34. >
  35. <byForm
  36. :formConfig="formConfig"
  37. :formOption="formOption"
  38. v-model="formData.data"
  39. :rules="rules"
  40. ref="byform"
  41. >
  42. <template #products>
  43. <div style="width: 100%">
  44. <el-button
  45. type="primary"
  46. @click="openProduct = true"
  47. style="margin-bottom: 10px"
  48. v-if="modalType == 'add'"
  49. >
  50. 添加产品
  51. </el-button>
  52. <el-table :data="formData.data.groupRecordDetailsList">
  53. <el-table-column prop="productName" label="产品名称" />
  54. <el-table-column
  55. prop="canSum"
  56. label="库存数量"
  57. v-if="modalType == 'add'"
  58. />
  59. <el-table-column prop="groupNum" label="拆分数量" min-width="150">
  60. <template #default="{ row, $index }">
  61. <el-form-item
  62. :prop="'groupRecordDetailsList.' + $index + '.groupNum'"
  63. :rules="rules.groupNum"
  64. :inline-message="true"
  65. >
  66. <el-input-number
  67. v-model="row.groupNum"
  68. :precision="0"
  69. :controls="false"
  70. :min="0"
  71. />
  72. </el-form-item>
  73. </template>
  74. </el-table-column>
  75. <el-table-column
  76. prop="zip"
  77. label="操作"
  78. width="100"
  79. v-if="modalType == 'add'"
  80. >
  81. <template #default="{ $index }">
  82. <el-button type="primary" link @click="handleRemove($index)"
  83. >删除</el-button
  84. >
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. </div>
  89. </template>
  90. </byForm>
  91. <template #footer v-if="modalType == 'add'">
  92. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  93. <el-button
  94. type="primary"
  95. @click="submitForm('byform')"
  96. size="large"
  97. :loading="submitLoading"
  98. >
  99. 确 定
  100. </el-button>
  101. </template>
  102. </el-dialog>
  103. <el-dialog
  104. v-model="openProduct"
  105. title="选择产品"
  106. width="70%"
  107. append-to-body
  108. >
  109. <SelectProduct @handleSelect="handleSelect"></SelectProduct>
  110. <template #footer>
  111. <span class="dialog-footer">
  112. <el-button @click="openProduct = false">取消</el-button>
  113. </span>
  114. </template>
  115. </el-dialog>
  116. </div>
  117. </template>
  118. <script setup>
  119. /* eslint-disable vue/no-unused-components */
  120. import { ElMessage, ElMessageBox } from "element-plus";
  121. import byTable from "@/components/byTable/index";
  122. import byForm from "@/components/byForm/index";
  123. import { computed, defineComponent, ref, watch } from "vue";
  124. import useUserStore from "@/store/modules/user";
  125. import SelectProduct from "@/components/WDLY/product/SelectProduct";
  126. const loading = ref(false);
  127. const submitLoading = ref(false);
  128. const sourceList = ref({
  129. data: [],
  130. pagination: {
  131. total: 3,
  132. pageNum: 1,
  133. pageSize: 10,
  134. type: "2",
  135. },
  136. });
  137. let dialogVisible = ref(false);
  138. let openProduct = ref(false);
  139. let roomDialogVisible = ref(false);
  140. let modalType = ref("add");
  141. let rules = ref({
  142. productWarehouseId: [
  143. { required: true, message: "请选择半成品所在仓库", trigger: "change" },
  144. ],
  145. groupWarehouseId: [
  146. { required: true, message: "请选择组合后放置仓库", trigger: "change" },
  147. ],
  148. groupNum: [{ required: true, message: "请输入分拆数量", trigger: "blur" }],
  149. });
  150. const { proxy } = getCurrentInstance();
  151. const selectConfig = reactive([]);
  152. const config = computed(() => {
  153. return [
  154. {
  155. attrs: {
  156. label: "组合编码",
  157. prop: "productCode",
  158. },
  159. },
  160. {
  161. attrs: {
  162. label: "组合名称",
  163. prop: "productName",
  164. },
  165. },
  166. {
  167. attrs: {
  168. label: "规格型号",
  169. prop: "productSpec",
  170. },
  171. },
  172. {
  173. attrs: {
  174. label: "拆分前所在仓库",
  175. prop: "groupWarehouseName",
  176. },
  177. },
  178. {
  179. attrs: {
  180. label: "拆分后放置仓库",
  181. prop: "productWarehouseName",
  182. },
  183. },
  184. {
  185. attrs: {
  186. label: "拆分数量",
  187. prop: "groupNum",
  188. },
  189. },
  190. {
  191. attrs: {
  192. label: "操作人",
  193. prop: "createUserName",
  194. },
  195. },
  196. {
  197. attrs: {
  198. label: "操作时间",
  199. prop: "createTime",
  200. },
  201. },
  202. {
  203. attrs: {
  204. label: "操作",
  205. width: "200",
  206. align: "right",
  207. },
  208. // 渲染 el-button,一般用在最后一列。
  209. renderHTML(row) {
  210. return [
  211. {
  212. attrs: {
  213. label: "查看",
  214. type: "primary",
  215. text: true,
  216. },
  217. el: "button",
  218. click() {
  219. getDtl(row);
  220. },
  221. },
  222. ];
  223. },
  224. },
  225. ];
  226. });
  227. let formData = reactive({
  228. data: {},
  229. treeData: [],
  230. });
  231. const formOption = reactive({
  232. inline: true,
  233. labelWidth: 100,
  234. itemWidth: 100,
  235. rules: [],
  236. });
  237. const byform = ref(null);
  238. const treeData = ref([]);
  239. const formConfig = reactive([
  240. {
  241. type: "title",
  242. title: "仓库信息",
  243. },
  244. {
  245. type: "select",
  246. prop: "groupWarehouseId",
  247. label: "拆分前所在仓库",
  248. itemWidth: 33,
  249. data: [],
  250. },
  251. {
  252. type: "select",
  253. prop: "productWarehouseId",
  254. label: "拆分后放置仓库",
  255. itemWidth: 33,
  256. data: [],
  257. },
  258. {
  259. type: "title",
  260. title: "拆分明细",
  261. },
  262. {
  263. type: "slot",
  264. slotName: "products",
  265. },
  266. ]);
  267. const getList = async (req) => {
  268. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  269. loading.value = true;
  270. proxy
  271. .post("/groupRecordDetails/page", sourceList.value.pagination)
  272. .then((message) => {
  273. console.log(message);
  274. sourceList.value.data = message.rows;
  275. sourceList.value.pagination.total = message.total;
  276. setTimeout(() => {
  277. loading.value = false;
  278. }, 200);
  279. });
  280. };
  281. const openModal = () => {
  282. dialogVisible.value = true;
  283. modalType.value = "add";
  284. formConfig[1].disabled = false;
  285. formConfig[2].disabled = false;
  286. formData.data = {
  287. type: "2",
  288. groupRecordDetailsList: [],
  289. };
  290. };
  291. const submitForm = () => {
  292. byform.value.handleSubmit((valid) => {
  293. const list = formData.data.groupRecordDetailsList;
  294. for (let i = 0; i < list.length; i++) {
  295. const e = list[i];
  296. if (e.groupNum == 0) {
  297. return ElMessage({
  298. message: "拆分数量不能为0!",
  299. type: "info",
  300. });
  301. }
  302. if (e.groupNum > Number(e.canSum)) {
  303. return ElMessage({
  304. message: "拆分数量不可大于库存数量!",
  305. type: "info",
  306. });
  307. }
  308. }
  309. submitLoading.value = true;
  310. const data = {
  311. type: formData.data.type,
  312. productWarehouseId: formData.data.productWarehouseId,
  313. groupWarehouseId: formData.data.groupWarehouseId,
  314. groupRecordDetailsList: list.map((x) => ({
  315. productId: x.productId,
  316. groupNum: x.groupNum,
  317. })),
  318. };
  319. proxy.post("/groupRecordDetails/" + modalType.value, data).then(
  320. (res) => {
  321. ElMessage({
  322. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  323. type: "success",
  324. });
  325. dialogVisible.value = false;
  326. submitLoading.value = false;
  327. getList();
  328. },
  329. (err) => (submitLoading.value = false)
  330. );
  331. });
  332. };
  333. const getDtl = (row) => {
  334. modalType.value = "edit";
  335. proxy
  336. .post("/groupRecordDetails/detail", { id: row.groupRecordId })
  337. .then((res) => {
  338. formConfig[1].disabled = true;
  339. formConfig[2].disabled = true;
  340. formData.data.productWarehouseId = row.productWarehouseId;
  341. formData.data.groupWarehouseId = row.groupWarehouseId;
  342. formData.data.groupRecordDetailsList = res;
  343. dialogVisible.value = true;
  344. });
  345. };
  346. const warehouseList = ref([]);
  347. const warehouseListData = () => {
  348. // // 币种数据
  349. proxy
  350. .post("/warehouse/page", {
  351. pageNum: 1,
  352. pageSize: 9999,
  353. })
  354. .then((message) => {
  355. warehouseList.value = message.rows;
  356. formConfig[1].data = message.rows.map((x) => ({
  357. label: x.name,
  358. value: x.id,
  359. }));
  360. formConfig[2].data = message.rows.map((x) => ({
  361. label: x.name,
  362. value: x.id,
  363. }));
  364. });
  365. };
  366. getList();
  367. warehouseListData();
  368. const handleSelect = (row) => {
  369. const flag = formData.data.groupRecordDetailsList.some(
  370. (x) => x.productId === row.id
  371. );
  372. if (flag)
  373. return ElMessage({
  374. message: "该物品已选择",
  375. type: "info",
  376. });
  377. formData.data.groupRecordDetailsList.push({
  378. productName: row.name,
  379. productCode: row.code,
  380. productSpec: row.spec,
  381. productId: row.id,
  382. groupNum: 0,
  383. });
  384. return ElMessage({
  385. message: "选择成功",
  386. type: "success",
  387. });
  388. };
  389. const handleRemove = (index) => {
  390. formData.data.groupRecordDetailsList.splice(index, 1);
  391. return ElMessage({
  392. message: "删除成功",
  393. type: "success",
  394. });
  395. };
  396. watchEffect(() => {
  397. const list = formData.data.groupRecordDetailsList;
  398. if (
  399. formData.data.groupWarehouseId &&
  400. list.length > 0 &&
  401. modalType.value == "add"
  402. ) {
  403. proxy
  404. .post("/stock/pageByWarehouse", {
  405. id: formData.data.groupWarehouseId,
  406. productIds: list.map((x) => x.productId),
  407. })
  408. .then((res) => {
  409. const productList = res.rows;
  410. for (let i = 0; i < list.length; i++) {
  411. const e = list[i];
  412. e.canSum = 0;
  413. for (let j = 0; j < productList.length; j++) {
  414. const x = productList[j];
  415. if (e.productId == x.productId) {
  416. e.canSum = x.quantity;
  417. }
  418. }
  419. }
  420. });
  421. }
  422. });
  423. </script>
  424. <style lang="scss" scoped>
  425. .tenant {
  426. padding: 20px;
  427. }
  428. </style>