index.vue 7.0 KB

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