index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="pageIndexClass">
  3. <div>
  4. <byTable :source="sourceList.data" :pagination="sourceList.pagination" :config="config" :loading="loading" highlight-current-row
  5. :selectConfig="selectConfig" :action-list="[
  6. {
  7. text: '添加店铺',
  8. action: () => openModal('add'),
  9. disabled: false,
  10. },
  11. ]" @get-list="getList">
  12. <template #name="{ item }">
  13. <div>
  14. <span class="el-click">{{ item.name }}</span>
  15. </div>
  16. </template>
  17. </byTable>
  18. </div>
  19. <el-dialog :title="modalType == 'add' ? '添加店铺' : '编辑店铺'" v-model="dialogVisible" width="500px" destroy-on-close>
  20. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="formDom" v-loading="submitLoading">
  21. </byForm>
  22. <template #footer>
  23. <el-button @click="dialogVisible = false" size="defualt" v-debounce>取 消</el-button>
  24. <el-button type="primary" @click="submitForm()" size="defualt" v-debounce :loading="submitLoading">
  25. 确 定
  26. </el-button>
  27. </template>
  28. </el-dialog>
  29. </div>
  30. </template>
  31. <script setup>
  32. import byTable from "@/components/byTable/index";
  33. import byForm from "@/components/byForm/index";
  34. const { proxy } = getCurrentInstance();
  35. const loading = ref(false);
  36. const submitLoading = ref(false);
  37. const sourceList = ref({
  38. data: [],
  39. pagination: {
  40. total: 3,
  41. pageNum: 1,
  42. pageSize: 10,
  43. keyword: "",
  44. },
  45. });
  46. const treeData = ref([]);
  47. const dialogVisible = ref(false);
  48. const modalType = ref("add");
  49. const selectConfig = computed(() => []);
  50. const config = computed(() => {
  51. return [
  52. {
  53. attrs: {
  54. label: "店铺编号",
  55. prop: "code",
  56. },
  57. },
  58. {
  59. attrs: {
  60. label: " 店铺名称",
  61. prop: "name",
  62. },
  63. },
  64. {
  65. attrs: {
  66. label: "负责部门",
  67. prop: "deptName",
  68. },
  69. },
  70. {
  71. attrs: {
  72. label: "操作",
  73. width: "120",
  74. align: "center",
  75. fixed: "right",
  76. },
  77. renderHTML(row) {
  78. return [
  79. {
  80. attrs: {
  81. label: "修改",
  82. type: "primary",
  83. text: true,
  84. },
  85. el: "button",
  86. click() {
  87. getDtl(row);
  88. },
  89. },
  90. {
  91. attrs: {
  92. label: "删除",
  93. type: "danger",
  94. text: true,
  95. },
  96. el: "button",
  97. click() {
  98. proxy
  99. .msgConfirm()
  100. .then((res) => {
  101. proxy
  102. .post("/shopInfo/delete", {
  103. id: row.id,
  104. })
  105. .then((res) => {
  106. proxy.msgTip("删除成功", 1);
  107. getList();
  108. });
  109. })
  110. .catch((err) => {});
  111. },
  112. },
  113. ];
  114. },
  115. },
  116. ];
  117. });
  118. const formData = reactive({
  119. data: {},
  120. });
  121. const formOption = reactive({
  122. inline: true,
  123. labelWidth: 100,
  124. itemWidth: 100,
  125. });
  126. const formDom = ref(null);
  127. const formConfig = computed(() => {
  128. return [
  129. {
  130. type: "input",
  131. prop: "code",
  132. label: "店铺编号",
  133. itemWidth: 100,
  134. disabled: false,
  135. },
  136. {
  137. type: "input",
  138. prop: "name",
  139. label: "店铺名称",
  140. itemWidth: 100,
  141. disabled: false,
  142. },
  143. {
  144. type: "treeSelect",
  145. prop: "deptId",
  146. label: "负责部门",
  147. data: treeData.value,
  148. propsTreeLabel: "deptName",
  149. propsTreeValue: "deptId",
  150. itemWidth: 100,
  151. disabled: false,
  152. },
  153. ];
  154. });
  155. const rules = ref({
  156. deptId: [{ required: true, message: "请选择负责部门", trigger: "change" }],
  157. name: [{ required: true, message: "请输入店铺名称", trigger: "blur" }],
  158. code: [{ required: true, message: "请输入店铺编号", trigger: "blur" }],
  159. });
  160. const getDeptData = () => {
  161. proxy
  162. .get("/tenantDept/list", {
  163. pageNum: 1,
  164. pageSize: 9999,
  165. keyword: "",
  166. tenantId: proxy.useUserStore().user.tenantId,
  167. })
  168. .then((res) => {
  169. treeData.value = proxy.handleTree(res.data, "deptId");
  170. });
  171. };
  172. getDeptData();
  173. const getList = async (req) => {
  174. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  175. loading.value = true;
  176. proxy.post("/shopInfo/page", sourceList.value.pagination).then((res) => {
  177. sourceList.value.data = res.rows;
  178. sourceList.value.pagination.total = res.total;
  179. setTimeout(() => {
  180. loading.value = false;
  181. }, 200);
  182. });
  183. };
  184. const openModal = () => {
  185. dialogVisible.value = true;
  186. modalType.value = "add";
  187. formData.data = {
  188. definition: "2",
  189. fileList: [],
  190. };
  191. if (currencyData.value && currencyData.value.length > 0) {
  192. formData.data.currency = currencyData.value[0].dictKey;
  193. formData.data.costCurrency = currencyData.value[0].dictKey;
  194. }
  195. };
  196. const submitForm = () => {
  197. formDom.value.handleSubmit((valid) => {
  198. submitLoading.value = true;
  199. proxy.post("/shopInfo/" + modalType.value, formData.data).then(
  200. (res) => {
  201. proxy.msgTip("操作成功", 1);
  202. dialogVisible.value = false;
  203. submitLoading.value = false;
  204. getList();
  205. },
  206. (err) => {
  207. submitLoading.value = false;
  208. }
  209. );
  210. });
  211. };
  212. const getDtl = (row) => {
  213. modalType.value = "edit";
  214. proxy.post("/shopInfo/detail", { id: row.id }).then((res) => {
  215. formData.data = res;
  216. dialogVisible.value = true;
  217. });
  218. };
  219. getList();
  220. </script>
  221. <style lang="scss" scoped>
  222. .content {
  223. padding: 20px;
  224. }
  225. </style>