index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <div class="tenant">
  3. <div class="content">
  4. <byTable
  5. :source="sourceList.data"
  6. :pagination="sourceList.pagination"
  7. :config="config"
  8. :loading="loading"
  9. :selectConfig="selectConfig"
  10. highlight-current-row
  11. :action-list="[
  12. {
  13. text: '新增调仓',
  14. action: () => openModal(),
  15. },
  16. ]"
  17. @get-list="getList">
  18. </byTable>
  19. </div>
  20. <el-dialog title="新增调仓" v-if="dialogVisible" v-model="dialogVisible" width="1000" v-loading="loadingDialog">
  21. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
  22. <template #details>
  23. <div style="width: 100%">
  24. <el-button type="primary" @click="openProduct = true">添加明细</el-button>
  25. <el-table :data="formData.data.list" style="width: 100%; margin-top: 16px">
  26. <el-table-column prop="productCode" label="产品编码" width="140" />
  27. <el-table-column prop="productName" label="产品名称" min-width="220" />
  28. <el-table-column prop="productSpec" label="规格型号" min-width="220" />
  29. <el-table-column prop="productUnit" label="单位" width="100" />
  30. <el-table-column label="入库数量" width="160">
  31. <template #default="{ row, $index }">
  32. <div style="width: 100%">
  33. <el-form-item :prop="'list.' + $index + '.quantity'" :rules="rules.quantity" :inline-message="true">
  34. <el-input-number v-model="row.quantity" placeholder="请输入数量" style="width: 100%" :precision="0" :controls="false" :min="0" />
  35. </el-form-item>
  36. </div>
  37. </template>
  38. </el-table-column>
  39. <el-table-column align="center" label="操作" width="80" fixed="right">
  40. <template #default="{ row, $index }">
  41. <el-button type="primary" link @click="handleDelete($index)">删除</el-button>
  42. </template>
  43. </el-table-column>
  44. </el-table>
  45. </div>
  46. </template>
  47. </byForm>
  48. <template #footer>
  49. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  50. <el-button type="primary" @click="submitForm()" size="large">确 定</el-button>
  51. </template>
  52. </el-dialog>
  53. <el-dialog v-model="openProduct" title="选择商品" width="70%" append-to-body>
  54. <SelectGoods @cancel="openProduct = false" @pushGoods="pushGoods"></SelectGoods>
  55. </el-dialog>
  56. </div>
  57. </template>
  58. <script setup>
  59. import { computed, ref } from "vue";
  60. import byTable from "@/components/byTable/index";
  61. import byForm from "@/components/byForm/index";
  62. import { ElMessage } from "element-plus";
  63. import SelectGoods from "@/components/product/SelectGoods";
  64. const { proxy } = getCurrentInstance();
  65. const warehouseList = ref([]);
  66. const sourceList = ref({
  67. data: [],
  68. pagination: {
  69. total: 0,
  70. pageNum: 1,
  71. pageSize: 10,
  72. keyword: "",
  73. warehouseId: "",
  74. toWarehouseId: "",
  75. type: "3,11",
  76. },
  77. });
  78. const loading = ref(false);
  79. const selectConfig = computed(() => {
  80. return [
  81. {
  82. label: "调出仓库",
  83. prop: "warehouseId",
  84. data: warehouseList.value,
  85. },
  86. {
  87. label: "调入仓库",
  88. prop: "toWarehouseId",
  89. data: warehouseList.value,
  90. },
  91. ];
  92. });
  93. const config = computed(() => {
  94. return [
  95. {
  96. attrs: {
  97. label: "单号",
  98. prop: "code",
  99. width: 160,
  100. },
  101. },
  102. {
  103. attrs: {
  104. label: "调出仓库",
  105. prop: "warehouseId",
  106. width: 220,
  107. },
  108. render(type) {
  109. return proxy.dictValueLabel(type, warehouseList.value);
  110. },
  111. },
  112. {
  113. attrs: {
  114. label: "调出仓库",
  115. prop: "toWarehouseId",
  116. width: 220,
  117. },
  118. render(type) {
  119. return proxy.dictValueLabel(type, warehouseList.value);
  120. },
  121. },
  122. {
  123. attrs: {
  124. label: "物品编码",
  125. prop: "productCode",
  126. width: 160,
  127. },
  128. },
  129. {
  130. attrs: {
  131. label: "物品名称",
  132. prop: "productName",
  133. "min-width": 220,
  134. },
  135. },
  136. {
  137. attrs: {
  138. label: "规格型号",
  139. prop: "productSpec",
  140. width: 160,
  141. },
  142. },
  143. {
  144. attrs: {
  145. label: "单位",
  146. prop: "productUnit",
  147. width: 120,
  148. },
  149. },
  150. {
  151. attrs: {
  152. label: "调仓数量",
  153. prop: "quantity",
  154. width: 140,
  155. },
  156. },
  157. {
  158. attrs: {
  159. label: "操作人",
  160. prop: "userName",
  161. width: 140,
  162. },
  163. },
  164. {
  165. attrs: {
  166. label: "操作时间",
  167. prop: "createTime",
  168. width: 160,
  169. },
  170. },
  171. ];
  172. });
  173. const getDict = () => {
  174. proxy.post("/warehouse/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  175. if (res.rows && res.rows.length > 0) {
  176. warehouseList.value = res.rows.map((item) => {
  177. return {
  178. label: item.name,
  179. value: item.id,
  180. };
  181. });
  182. }
  183. });
  184. };
  185. const getList = async (req) => {
  186. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  187. loading.value = true;
  188. proxy.post("/stockJournalDetails/page", sourceList.value.pagination).then((res) => {
  189. sourceList.value.data = res.rows;
  190. sourceList.value.pagination.total = res.total;
  191. setTimeout(() => {
  192. loading.value = false;
  193. }, 200);
  194. });
  195. };
  196. getDict();
  197. getList();
  198. const dialogVisible = ref(false);
  199. const loadingDialog = ref(false);
  200. const submit = ref(null);
  201. const openProduct = ref(false);
  202. const formOption = reactive({
  203. inline: true,
  204. labelWidth: 100,
  205. itemWidth: 100,
  206. rules: [],
  207. });
  208. const formData = reactive({
  209. data: {},
  210. });
  211. const formConfig = computed(() => {
  212. return [
  213. {
  214. label: "基本信息",
  215. },
  216. {
  217. type: "select",
  218. prop: "warehouseId",
  219. label: "调出仓库",
  220. required: true,
  221. data: warehouseList.value,
  222. itemWidth: 30,
  223. },
  224. {
  225. type: "select",
  226. prop: "toWarehouseId",
  227. label: "调入仓库",
  228. required: true,
  229. data: warehouseList.value,
  230. itemWidth: 30,
  231. },
  232. {
  233. type: "input",
  234. prop: "remark",
  235. label: "调仓说明",
  236. itemType: "textarea",
  237. },
  238. {
  239. type: "slot",
  240. slotName: "details",
  241. label: "入库明细",
  242. },
  243. ];
  244. });
  245. const rules = ref({
  246. warehouseId: [{ required: true, message: "请选择仓库", trigger: "change" }],
  247. });
  248. const openModal = () => {
  249. formData.data = {
  250. type: "1",
  251. list: [],
  252. };
  253. loadingDialog.value = false;
  254. dialogVisible.value = true;
  255. };
  256. const pushGoods = (goods) => {
  257. if (goods && goods.length > 0) {
  258. formData.data.list = formData.data.list.concat(
  259. goods.map((item) => {
  260. return {
  261. productCode: item.code,
  262. productId: item.id,
  263. productName: item.name,
  264. productSpec: item.spec,
  265. productUnit: item.unit,
  266. quantity: undefined,
  267. };
  268. })
  269. );
  270. ElMessage({
  271. message: "添加成功!",
  272. type: "success",
  273. });
  274. openProduct.value = false;
  275. } else {
  276. ElMessage("请选择至少一件产品");
  277. }
  278. };
  279. const submitForm = () => {
  280. submit.value.handleSubmit(() => {
  281. loadingDialog.value = true;
  282. proxy.post("/stock/stockTransfer", formData.data).then(
  283. () => {
  284. ElMessage({
  285. message: "提交成功",
  286. type: "success",
  287. });
  288. dialogVisible.value = false;
  289. getList();
  290. },
  291. (err) => {
  292. console.log(err);
  293. loadingDialog.value = false;
  294. }
  295. );
  296. });
  297. };
  298. const handleDelete = (index) => {
  299. formData.data.list.splice(index, 1);
  300. };
  301. </script>
  302. <style lang="scss" scoped>
  303. .tenant {
  304. padding: 20px;
  305. }
  306. ::v-deep(.el-input-number .el-input__inner) {
  307. text-align: left;
  308. }
  309. </style>