index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. </byForm>
  43. <template #footer>
  44. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  45. <el-button
  46. type="primary"
  47. v-no-double-click="submitForm"
  48. size="large"
  49. :loading="submitLoading"
  50. >
  51. 确 定
  52. </el-button>
  53. </template>
  54. </el-dialog>
  55. </div>
  56. </template>
  57. <script setup>
  58. /* eslint-disable vue/no-unused-components */
  59. import { ElMessage, ElMessageBox } from "element-plus";
  60. import byTable from "@/components/byTable/index";
  61. import byForm from "@/components/byForm/index";
  62. import { computed, defineComponent, ref } from "vue";
  63. import useUserStore from "@/store/modules/user";
  64. const loading = ref(false);
  65. const submitLoading = ref(false);
  66. const sourceList = ref({
  67. data: [],
  68. pagination: {
  69. total: 3,
  70. pageNum: 1,
  71. pageSize: 10,
  72. },
  73. });
  74. let dialogVisible = ref(false);
  75. let roomDialogVisible = ref(false);
  76. let modalType = ref("add");
  77. let rules = ref({
  78. type: [
  79. { required: true, message: "请选择仓库类型", trigger: ["blur", "change"] },
  80. ],
  81. name: [{ required: true, message: "请输入仓库名称", trigger: "blur" }],
  82. });
  83. const { proxy } = getCurrentInstance();
  84. const selectConfig = reactive([
  85. {
  86. label: "仓库类型",
  87. prop: "type",
  88. data: [],
  89. },
  90. ]);
  91. const config = computed(() => {
  92. return [
  93. {
  94. attrs: {
  95. label: "仓库名称",
  96. prop: "name",
  97. },
  98. },
  99. {
  100. attrs: {
  101. label: "仓库类型",
  102. prop: "type",
  103. },
  104. render(type) {
  105. return proxy.dictDataEcho(type, warehouseType.value);
  106. },
  107. },
  108. {
  109. attrs: {
  110. label: "仓管员名称",
  111. prop: "keeperName",
  112. },
  113. },
  114. {
  115. attrs: {
  116. label: "备注",
  117. prop: "remark",
  118. },
  119. },
  120. {
  121. attrs: {
  122. label: "操作",
  123. width: "200",
  124. align: "right",
  125. },
  126. // 渲染 el-button,一般用在最后一列。
  127. renderHTML(row) {
  128. return [
  129. {
  130. attrs: {
  131. label: "修改",
  132. type: "primary",
  133. text: true,
  134. },
  135. el: "button",
  136. click() {
  137. getDtl(row);
  138. },
  139. },
  140. {
  141. attrs: {
  142. label: "删除",
  143. type: "danger",
  144. text: true,
  145. },
  146. el: "button",
  147. click() {
  148. // 弹窗提示是否删除
  149. ElMessageBox.confirm(
  150. "此操作将永久删除该数据, 是否继续?",
  151. "提示",
  152. {
  153. confirmButtonText: "确定",
  154. cancelButtonText: "取消",
  155. type: "warning",
  156. }
  157. ).then(() => {
  158. // 删除
  159. proxy
  160. .post("/warehouse/delete", {
  161. id: row.id,
  162. })
  163. .then((res) => {
  164. ElMessage({
  165. message: "删除成功",
  166. type: "success",
  167. });
  168. getList();
  169. });
  170. });
  171. },
  172. },
  173. ];
  174. },
  175. },
  176. ];
  177. });
  178. let formData = reactive({
  179. data: {},
  180. treeData: [],
  181. });
  182. const formOption = reactive({
  183. inline: true,
  184. labelWidth: 100,
  185. itemWidth: 100,
  186. rules: [],
  187. });
  188. const byform = ref(null);
  189. const treeData = ref([]);
  190. const formConfig = reactive([
  191. {
  192. type: "select",
  193. prop: "type",
  194. label: "仓库类型",
  195. required: true,
  196. data: [],
  197. },
  198. {
  199. type: "input",
  200. prop: "name",
  201. label: "仓库名称",
  202. },
  203. {
  204. type: "select",
  205. prop: "keeperId",
  206. label: "仓管员",
  207. isLoad: {
  208. url: `/tenantUser/list?pageNum=1&pageSize=9999&tenantId=${
  209. useUserStore().user.tenantId
  210. }`,
  211. labelKey: "nickName",
  212. labelVal: "userId",
  213. method: "get",
  214. resUrl: "rows",
  215. },
  216. },
  217. {
  218. type: "input",
  219. itemType: "textarea",
  220. prop: "remark",
  221. label: "备注",
  222. },
  223. ]);
  224. const getList = async (req) => {
  225. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  226. loading.value = true;
  227. proxy.post("/warehouse/page", sourceList.value.pagination).then((message) => {
  228. console.log(message);
  229. sourceList.value.data = message.rows;
  230. sourceList.value.pagination.total = message.total;
  231. setTimeout(() => {
  232. loading.value = false;
  233. }, 200);
  234. });
  235. };
  236. const openModal = () => {
  237. dialogVisible.value = true;
  238. modalType.value = "add";
  239. formData.data = {};
  240. };
  241. const submitForm = () => {
  242. console.log(byform.value);
  243. byform.value.handleSubmit((valid) => {
  244. submitLoading.value = true;
  245. proxy.post("/warehouse/" + modalType.value, formData.data).then(
  246. (res) => {
  247. ElMessage({
  248. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  249. type: "success",
  250. });
  251. dialogVisible.value = false;
  252. submitLoading.value = false;
  253. getList();
  254. },
  255. (err) => (submitLoading.value = false)
  256. );
  257. });
  258. };
  259. const getDtl = (row) => {
  260. modalType.value = "edit";
  261. proxy.post("/warehouse/detail", { id: row.id }).then((res) => {
  262. res.type = res.type + "";
  263. dialogVisible.value = true;
  264. formData.data = res;
  265. });
  266. };
  267. const warehouseType = ref([]);
  268. const getDict = () => {
  269. // // 币种数据
  270. proxy
  271. .post("/dictTenantData/page", {
  272. pageNum: 1,
  273. pageSize: 999,
  274. tenantId: useUserStore().user.tenantId,
  275. dictCode: "warehouse_type",
  276. })
  277. .then((res) => {
  278. warehouseType.value = res.rows;
  279. selectConfig[0].data = res.rows.map((x) => ({
  280. label: x.dictValue,
  281. value: x.dictKey,
  282. }));
  283. formConfig[0].data = res.rows.map((x) => ({
  284. label: x.dictValue,
  285. value: x.dictKey,
  286. }));
  287. });
  288. };
  289. getList();
  290. getDict();
  291. </script>
  292. <style lang="scss" scoped>
  293. .tenant {
  294. padding: 20px;
  295. }
  296. </style>