put-ad-account.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div class="page-wrap page-wrap-put-books">
  3. <tool-bar
  4. :text="['email', 'account_id', 'account_name', 'advertiser_id']"
  5. :label="['邮箱', '账户名/ID', '用户名', '广告主ID']"
  6. v-model:loading="inSearching"
  7. @confirm="onSearch"
  8. >
  9. <template #exbutton>
  10. <a-button type="primary" @click="handleClick" class="ml-10">
  11. 授权
  12. </a-button>
  13. </template>
  14. </tool-bar>
  15. <a-table
  16. :columns="columns"
  17. :data-source="list"
  18. :pagination="tablePageOptions"
  19. :loading="loading.value"
  20. bordered
  21. @change="handleTableChange"
  22. :scroll="{ y: 600 }"
  23. rowKey="id"
  24. >
  25. <template #operator="{ text, record }">
  26. <a-switch
  27. v-model:checked="record.is_enable"
  28. @change="switchMethod(record)"
  29. />
  30. </template>
  31. <template #email="{ text, record }">
  32. <p>账户ID{{ record.account_id }}</p>
  33. <p>邮箱:{{ record.email }}</p>
  34. </template>
  35. </a-table>
  36. </div>
  37. </template>
  38. <script lang="ts">
  39. import { defineComponent, reactive, toRefs, ref } from "vue";
  40. import ToolBar from "@/components/tool-bar/index.vue";
  41. import { TableColumnOfPutAdAccount } from "../_pageOptions/table-put";
  42. import usePagination from "@/hooks/usePagination";
  43. import { getAdPushList, getAdauth, statusAdChange } from "@/api";
  44. import { ADpushSimple, PageOptions } from "@/types/api";
  45. import useDebounceFn from "@/hooks/useDebounceFn";
  46. import { message } from "ant-design-vue";
  47. const PutAdAccount = defineComponent({
  48. components: {
  49. ToolBar,
  50. },
  51. setup() {
  52. let { loading, meta, tablePageOptions } = usePagination();
  53. const state = reactive({
  54. list: ref<ADpushSimple[]>([]),
  55. columns: TableColumnOfPutAdAccount,
  56. inSearching: false,
  57. loading,
  58. tablePageOptions,
  59. });
  60. getAdPushList({ page: 1 }).then((res) => {
  61. let clist = res.data.list.map((r: any) => {
  62. r.is_enable == 0 ? (r.is_enable = false) : (r.is_enable = true);
  63. return r;
  64. });
  65. state.list = clist;
  66. meta.value = res.data.meta;
  67. });
  68. const onSearch = async (fields: Record<string, string>) => {
  69. try {
  70. const { email, account_name, account_id, advertiser_id } = fields;
  71. const { data } = await getAdPushList({
  72. email,
  73. account_name,
  74. account_id,
  75. advertiser_id,
  76. page: 1,
  77. });
  78. let clist = data.list.map((r: any) => {
  79. r.is_enable == 0 ? (r.is_enable = false) : (r.is_enable = true);
  80. return r;
  81. });
  82. console.log(clist);
  83. state.list = clist;
  84. meta.value = data.meta;
  85. } catch (e) {
  86. console.log(e);
  87. } finally {
  88. state.inSearching = false;
  89. }
  90. };
  91. const switchMethod = (record: any) => {
  92. let data = {
  93. advertiser_id: record.advertiser_id,
  94. is_enable: Number(!record.is_enable),
  95. };
  96. statusAdChange(data).then((res) => {
  97. message.success("修改成功!");
  98. });
  99. };
  100. const handleTableChange = (pagination: PageOptions) => {
  101. const { current, pageSize, total } = pagination;
  102. getAdPushList({ page: current }).then((res) => {
  103. state.list = res.data.list;
  104. meta.value = res.data.meta;
  105. });
  106. };
  107. return { ...toRefs(state), onSearch, handleTableChange, switchMethod };
  108. },
  109. methods: {
  110. async handleClick() {
  111. let res: any = await getAdauth();
  112. if (res.data && res.data.url) {
  113. window.open(res.data.url);
  114. } else {
  115. this.$message.error("暂未配置授权地址");
  116. }
  117. },
  118. },
  119. });
  120. export default PutAdAccount;
  121. </script>