index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <script setup lang="ts">
  2. import { ref } from "vue";
  3. import Modal from "./components/modal.vue";
  4. import contentConfig from "./config/content.config";
  5. import searchConfig from "./config/search.config";
  6. import { usePageSearch, type PageHooks, type PageEvents } from "/@/hooks/page";
  7. import { httpAdd, httpUpdate } from "/@/api/serviceParam/paymentChannelManage";
  8. import { ElMessage } from "element-plus"
  9. const PageName = "paymentChannelManage";
  10. const instance = ref<any>(null);
  11. const disabled = ref(false)
  12. const visible = ref(false)
  13. const data = ref<any>({})
  14. const hooks: PageHooks = {
  15. pageSearchHook: () => usePageSearch(undefined, undefined, searchConfig)
  16. };
  17. const events: PageEvents = {
  18. content: {
  19. create: () => {
  20. disabled.value = false
  21. visible.value = true
  22. },
  23. preview: _data => {
  24. data.value = {..._data}
  25. disabled.value = true
  26. visible.value = true
  27. },
  28. update: _data => {
  29. data.value = {..._data}
  30. disabled.value = false
  31. visible.value = true
  32. }
  33. }
  34. };
  35. async function onSubmit() {
  36. const { id, channel_name, companyNo } = data.value;
  37. const isCreate = id === undefined
  38. console.log(isCreate)
  39. const params = { id, channel_name,companyNo }
  40. if(isCreate) delete params['id']
  41. const api = isCreate ? httpAdd : httpUpdate
  42. const result = await api(params)
  43. if(result.code === 0){
  44. visible.value = false
  45. ElMessage.success(`${isCreate ? '添加' : '更新'}成功`)
  46. instance.value!.onSearch()
  47. }else{
  48. ElMessage.warning(`${isCreate ? '添加' : '更新'}失败`)
  49. }
  50. }
  51. </script>
  52. <template>
  53. <PageAuth :pageName="PageName">
  54. <PageContainer
  55. :hooks="hooks"
  56. :events="events"
  57. :contentConfig="contentConfig"
  58. :search-config="searchConfig"
  59. :get-content-ref="ref => (instance = ref)"
  60. />
  61. <Modal v-model:visible="visible" v-model:data="data" :disabled="disabled" @submit="onSubmit" />
  62. </PageAuth>
  63. </template>