index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="tenant">
  3. <!-- <Banner /> -->
  4. <div style="background: #fff">
  5. <el-tabs
  6. v-model="activeName"
  7. type="card"
  8. class="demo-tabs"
  9. @tab-change="handleChange"
  10. >
  11. <el-tab-pane label="按仓库" name="first"></el-tab-pane>
  12. <el-tab-pane label="按产品" name="second"></el-tab-pane>
  13. </el-tabs>
  14. <byTable
  15. :source="sourceList.data"
  16. :pagination="sourceList.pagination"
  17. :config="config"
  18. :loading="loading"
  19. highlight-current-row
  20. :selectConfig="selectConfig"
  21. :table-events="{
  22. //element talbe事件都能传
  23. select: select,
  24. }"
  25. :action-list="[]"
  26. @get-list="getList"
  27. >
  28. </byTable>
  29. </div>
  30. <el-dialog
  31. :title="modalType == 'add' ? '良品转次品' : '次品转良品'"
  32. v-model="dialogVisible"
  33. width="800"
  34. v-loading="loading"
  35. >
  36. <byForm
  37. :formConfig="formConfig"
  38. :formOption="formOption"
  39. v-model="formData.data"
  40. :rules="rules"
  41. ref="byform"
  42. >
  43. </byForm>
  44. <template #footer>
  45. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  46. <el-button
  47. type="primary"
  48. @click="submitForm('byform')"
  49. size="large"
  50. :loading="submitLoading"
  51. >
  52. 确 定
  53. </el-button>
  54. </template>
  55. </el-dialog>
  56. </div>
  57. </template>
  58. <script setup>
  59. /* eslint-disable vue/no-unused-components */
  60. import { ElMessage, ElMessageBox } from "element-plus";
  61. import byTable from "@/components/byTable/index";
  62. import byForm from "@/components/byForm/index";
  63. import { computed, defineComponent, ref } from "vue";
  64. import useUserStore from "@/store/modules/user";
  65. import SelectProduct from "@/components/product/SelectProduct";
  66. const loading = ref(false);
  67. let activeName = ref("first");
  68. const submitLoading = ref(false);
  69. const sourceList = ref({
  70. data: [],
  71. pagination: {
  72. total: 3,
  73. pageNum: 1,
  74. pageSize: 10,
  75. },
  76. });
  77. let dialogVisible = ref(false);
  78. let openProduct = ref(false);
  79. let roomDialogVisible = ref(false);
  80. let modalType = ref("add");
  81. let rules = ref({
  82. qualified: [{ required: true, message: "请输入数量", trigger: "blur" }],
  83. });
  84. const { proxy } = getCurrentInstance();
  85. const selectConfig = reactive([
  86. // {
  87. // label: "spu类型",
  88. // prop: "type",
  89. // data: [],
  90. // },
  91. ]);
  92. const config = reactive([
  93. {
  94. attrs: {
  95. label: "仓库名称",
  96. prop: "warehouseName",
  97. },
  98. },
  99. {
  100. attrs: {
  101. label: "产品编码",
  102. prop: "code",
  103. },
  104. },
  105. {
  106. attrs: {
  107. label: "产品名称",
  108. prop: "productName",
  109. },
  110. },
  111. {
  112. attrs: {
  113. label: "规格",
  114. prop: "spec",
  115. },
  116. },
  117. {
  118. attrs: {
  119. label: "单位",
  120. prop: "unit",
  121. },
  122. },
  123. {
  124. attrs: {
  125. label: "可用库存",
  126. prop: "quantity",
  127. },
  128. },
  129. {
  130. attrs: {
  131. label: "冻结库存",
  132. prop: "frozenQuantity",
  133. },
  134. },
  135. {
  136. attrs: {
  137. label: "次品",
  138. prop: "defectiveQuantity",
  139. },
  140. },
  141. {
  142. attrs: {
  143. label: "操作",
  144. width: "200",
  145. align: "right",
  146. },
  147. // 渲染 el-button,一般用在最后一列。
  148. renderHTML(row) {
  149. return [
  150. {
  151. attrs: {
  152. label: "良转次",
  153. type: "primary",
  154. text: true,
  155. },
  156. el: "button",
  157. click() {
  158. getDtl(row, "add");
  159. },
  160. },
  161. {
  162. attrs: {
  163. label: "次转良",
  164. type: "primary",
  165. text: true,
  166. },
  167. el: "button",
  168. click() {
  169. getDtl(row, "edit");
  170. },
  171. },
  172. ];
  173. },
  174. },
  175. ]);
  176. let formData = reactive({
  177. data: {},
  178. treeData: [],
  179. });
  180. const formOption = reactive({
  181. inline: true,
  182. labelWidth: 100,
  183. itemWidth: 100,
  184. rules: [],
  185. });
  186. const formConfig = reactive([
  187. {
  188. type: "input",
  189. prop: "canSum",
  190. label: "可转数量",
  191. disabled: true,
  192. },
  193. {
  194. type: "input",
  195. prop: "qualified",
  196. label: "数量",
  197. },
  198. ]);
  199. const byform = ref(null);
  200. let requestUrl = "/stock/pageByWarehouse";
  201. const getList = async (req) => {
  202. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  203. loading.value = true;
  204. proxy.post(requestUrl, sourceList.value.pagination).then((message) => {
  205. console.log(message);
  206. sourceList.value.data = message.rows.map((x) => ({
  207. ...x,
  208. ...JSON.parse(x.victoriatouristJson),
  209. }));
  210. sourceList.value.pagination.total = message.total;
  211. setTimeout(() => {
  212. loading.value = false;
  213. }, 200);
  214. });
  215. };
  216. const submitForm = () => {
  217. let submitAddress =
  218. modalType.value === "add"
  219. ? "/stock/defectiveToQualified"
  220. : "/stock/qualifiedToDefective";
  221. byform.value.handleSubmit((valid) => {
  222. if (Number(formData.data.qualified) > Number(formData.data.canSum)) {
  223. return ElMessage({
  224. message: "不可大于可转数量!",
  225. type: "info",
  226. });
  227. }
  228. submitLoading.value = true;
  229. proxy.post(submitAddress, formData.data).then(
  230. (res) => {
  231. ElMessage({
  232. message: "操作成功",
  233. type: "success",
  234. });
  235. dialogVisible.value = false;
  236. submitLoading.value = false;
  237. getList();
  238. },
  239. (err) => (submitLoading.value = false)
  240. );
  241. });
  242. };
  243. const getDtl = (row, type) => {
  244. modalType.value = type;
  245. let canSum = type === "add" ? row.quantity : row.defectiveQuantity;
  246. formData.data = {
  247. id: row.id,
  248. canSum,
  249. qualified: "",
  250. };
  251. dialogVisible.value = true;
  252. };
  253. getList();
  254. const handleChange = () => {
  255. sourceList.value.pagination.pageNum = 1;
  256. if (activeName.value === "first") {
  257. requestUrl = "/stock/pageByWarehouse";
  258. config.unshift({
  259. attrs: {
  260. label: "仓库名称",
  261. prop: "warehouseName",
  262. },
  263. });
  264. } else {
  265. requestUrl = "/stock/pageByProduct";
  266. config.shift();
  267. }
  268. getList();
  269. };
  270. </script>
  271. <style lang="scss" scoped>
  272. .tenant {
  273. padding: 20px;
  274. }
  275. </style>