index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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="code" label="产品编码" width="140" />
  27. <el-table-column prop="productName" label="产品名称" min-width="220" />
  28. <el-table-column prop="productModel" label="规格型号" min-width="220" />
  29. <el-table-column prop="unit" 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. type: "1",
  74. },
  75. });
  76. const loading = ref(false);
  77. const selectConfig = computed(() => {
  78. return [
  79. {
  80. label: "仓库名称",
  81. prop: "warehouseId",
  82. data: warehouseList.value,
  83. },
  84. ];
  85. });
  86. const config = computed(() => {
  87. return [
  88. {
  89. attrs: {
  90. label: "仓库名称",
  91. prop: "warehouseId",
  92. width: 220,
  93. },
  94. render(type) {
  95. return proxy.dictValueLabel(type, warehouseList.value);
  96. },
  97. },
  98. {
  99. attrs: {
  100. label: "物品编码",
  101. prop: "productCode",
  102. width: 160,
  103. },
  104. },
  105. {
  106. attrs: {
  107. label: "物品名称",
  108. slot: "productName",
  109. "min-width": 220,
  110. },
  111. },
  112. {
  113. attrs: {
  114. label: "规格型号",
  115. prop: "productModel",
  116. width: 160,
  117. },
  118. },
  119. {
  120. attrs: {
  121. label: "单位",
  122. prop: "unit",
  123. width: 120,
  124. },
  125. },
  126. {
  127. attrs: {
  128. label: "入库数量",
  129. prop: "quantity",
  130. width: 140,
  131. },
  132. },
  133. {
  134. attrs: {
  135. label: "操作人",
  136. prop: "userName",
  137. width: 140,
  138. },
  139. },
  140. {
  141. attrs: {
  142. label: "操作时间",
  143. prop: "createTime",
  144. width: 160,
  145. },
  146. },
  147. ];
  148. });
  149. const getDict = () => {
  150. proxy.post("/warehouse/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  151. if (res.rows && res.rows.length > 0) {
  152. warehouseList.value = res.rows.map((item) => {
  153. return {
  154. label: item.name,
  155. value: item.id,
  156. };
  157. });
  158. }
  159. });
  160. };
  161. const getList = async (req) => {
  162. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  163. loading.value = true;
  164. proxy.post("/stockJournal/page", sourceList.value.pagination).then((res) => {
  165. sourceList.value.data = res.rows;
  166. sourceList.value.pagination.total = res.total;
  167. setTimeout(() => {
  168. loading.value = false;
  169. }, 200);
  170. });
  171. };
  172. getDict();
  173. getList();
  174. const dialogVisible = ref(false);
  175. const loadingDialog = ref(false);
  176. const submit = ref(null);
  177. const openProduct = ref(false);
  178. const formOption = reactive({
  179. inline: true,
  180. labelWidth: 100,
  181. itemWidth: 100,
  182. rules: [],
  183. });
  184. const formData = reactive({
  185. data: {},
  186. });
  187. const formConfig = computed(() => {
  188. return [
  189. {
  190. label: "基本信息",
  191. },
  192. {
  193. type: "select",
  194. prop: "warehouseId",
  195. label: "仓库名称",
  196. required: true,
  197. data: warehouseList.value,
  198. },
  199. {
  200. type: "slot",
  201. slotName: "details",
  202. label: "入库明细",
  203. },
  204. ];
  205. });
  206. const rules = ref({
  207. warehouseId: [{ required: true, message: "请选择仓库", trigger: "change" }],
  208. });
  209. const openModal = () => {
  210. formData.data = {
  211. type: "1",
  212. list: [],
  213. };
  214. loadingDialog.value = false;
  215. dialogVisible.value = true;
  216. };
  217. const pushGoods = (goods) => {
  218. if (goods && goods.length > 0) {
  219. formData.data.list = formData.data.list.concat(
  220. goods.map((item) => {
  221. return {
  222. code: item.code,
  223. productId: item.id,
  224. productName: item.name,
  225. productModel: item.spec,
  226. unit: item.unit,
  227. quantity: undefined,
  228. };
  229. })
  230. );
  231. ElMessage({
  232. message: "添加成功!",
  233. type: "success",
  234. });
  235. openProduct.value = false;
  236. } else {
  237. ElMessage("请选择至少一件产品");
  238. }
  239. };
  240. const submitForm = () => {
  241. submit.value.handleSubmit(() => {
  242. loadingDialog.value = true;
  243. proxy.post("/stock/add", formData.data).then(
  244. () => {
  245. ElMessage({
  246. message: "提交成功",
  247. type: "success",
  248. });
  249. dialogVisible.value = false;
  250. getList();
  251. },
  252. (err) => {
  253. console.log(err);
  254. loadingDialog.value = false;
  255. }
  256. );
  257. });
  258. };
  259. const handleDelete = (index) => {
  260. formData.data.list.splice(index, 1);
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. .tenant {
  265. padding: 20px;
  266. }
  267. ::v-deep(.el-input-number .el-input__inner) {
  268. text-align: left;
  269. }
  270. </style>