index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div class="auxiliary-special-number-container layout-padding">
  3. <div class="layout-padding-auto layout-padding-view pd20">
  4. <el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
  5. <el-form-item label="电话号码" prop="PhoneNumber">
  6. <el-input v-model="state.queryParams.PhoneNumber" placeholder="请填写电话号码" clearable @keyup.enter="handleQuery" class="keyword-input" />
  7. </el-form-item>
  8. <el-form-item>
  9. <el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
  10. <el-button @click="resetQuery(ruleFormRef)" class="default-button"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
  11. </el-form-item>
  12. </el-form>
  13. <vxe-toolbar
  14. ref="toolbarRef"
  15. :loading="state.loading"
  16. custom
  17. :refresh="{
  18. queryMethod: handleQuery,
  19. }"
  20. >
  21. <template #buttons>
  22. <el-button type="primary" @click="onAdd" v-auth="'auxiliary:specialNumber:add'">
  23. <SvgIcon name="ele-Plus" class="mr5" />新增特殊号码
  24. </el-button>
  25. </template>
  26. </vxe-toolbar>
  27. <div style="overflow: hidden; width: 100%; height: 100%; flex: 1">
  28. <vxe-table
  29. border
  30. :loading="state.loading"
  31. :data="state.tableData"
  32. :column-config="{ resizable: true, useKey: true }"
  33. :row-config="{ isCurrent: true, isHover: true, useKey: true, height: 30 }"
  34. ref="tableRef"
  35. height="auto"
  36. auto-resize
  37. show-overflow
  38. :scrollY="{ enabled: true, gt: 100 }"
  39. id="auxiliarySpecialNumber"
  40. :custom-config="{ storage: true }"
  41. :sort-config="{ remote: true }"
  42. @sort-change="sortChange"
  43. >
  44. <vxe-column field="phoneNumber" title="电话号码"></vxe-column>
  45. <vxe-column field="notes" title="备注" min-width="200"></vxe-column>
  46. <vxe-column field="creationTime" title="创建时间" width="160" sortable>
  47. <template #default="{ row }">
  48. {{ formatDate(row.creationTime, 'YYYY-mm-dd HH:MM:SS') }}
  49. </template>
  50. </vxe-column>
  51. <vxe-column title="操作" fixed="right" width="130" align="center">
  52. <template #default="{ row }">
  53. <el-button link type="primary" @click="onEdit(row)" v-auth="'auxiliary:specialNumber:edit'" title="编辑"> 编辑 </el-button>
  54. <el-button link type="danger" @click="onDelete(row)" v-auth="'auxiliary:specialNumber:delete'" title="删除"> 删除 </el-button>
  55. </template>
  56. </vxe-column>
  57. </vxe-table>
  58. </div>
  59. <pagination
  60. @pagination="queryList"
  61. :total="state.total"
  62. v-model:current-page="state.queryParams.PageIndex"
  63. v-model:page-size="state.queryParams.PageSize"
  64. :disabled="state.loading"
  65. />
  66. </div>
  67. <!-- 新增 -->
  68. <special-number-add ref="specialNumberAddRef" @updateList="queryList" />
  69. <!-- 编辑 -->
  70. <special-number-edit ref="specialNumberEditRef" @updateList="queryList" />
  71. </div>
  72. </template>
  73. <script lang="tsx" setup name="auxiliarySpecialNumber">
  74. import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
  75. import { ElMessage, ElMessageBox, FormInstance } from 'element-plus';
  76. import { formatDate } from '@/utils/formatTime';
  77. import { deleteSpecialNumber, getSpecialNumberList } from '@/api/auxiliary/specialNumber';
  78. // 引入组件
  79. const SpecialNumberAdd = defineAsyncComponent(() => import('@/views/auxiliary/specialNumber/components/Number-add.vue')); // 新增
  80. const SpecialNumberEdit = defineAsyncComponent(() => import('@/views/auxiliary/specialNumber/components/Number-edit.vue')); // 编辑
  81. const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页
  82. // 定义变量内容
  83. const state = reactive({
  84. loading: false, // 加载状态
  85. queryParams: {
  86. // 查询参数
  87. PageIndex: 1,
  88. PageSize: 20,
  89. PhoneNumber: null, // 电话号码
  90. SortField: null,
  91. SortRule: null,
  92. },
  93. total: 0, // 总条数
  94. tableData: [], // 表格数据
  95. });
  96. const ruleFormRef = ref<any>(null); // 表单ref
  97. /** 搜索按钮操作 */
  98. const handleQuery = () => {
  99. state.queryParams.PageIndex = 1;
  100. queryList();
  101. };
  102. // 获取列表
  103. const queryList = () => {
  104. state.loading = true;
  105. getSpecialNumberList(state.queryParams)
  106. .then((res) => {
  107. state.loading = false;
  108. state.tableData = res.result.items ?? [];
  109. state.total = res.result.total ?? 0;
  110. })
  111. .finally(() => {
  112. state.loading = false;
  113. });
  114. };
  115. // 排序
  116. const sortChange = (val: any) => {
  117. state.queryParams.SortField = val.order ? val.field : null;
  118. // 0 升序 1 降序
  119. state.queryParams.SortRule = val.order ? (val.order == 'desc' ? 1 : 0) : null;
  120. queryList();
  121. };
  122. // 重置表单
  123. const resetQuery = (formEl: FormInstance | undefined) => {
  124. if (!formEl) return;
  125. formEl.resetFields();
  126. queryList();
  127. };
  128. // 新增
  129. const specialNumberAddRef = ref<RefType>();
  130. const onAdd = () => {
  131. specialNumberAddRef.value.openDialog();
  132. };
  133. // 修改
  134. const specialNumberEditRef = ref<RefType>();
  135. const onEdit = (row: any) => {
  136. specialNumberEditRef.value.openDialog(row.id);
  137. };
  138. // 删除
  139. const onDelete = (row: any) => {
  140. ElMessageBox.confirm(`您确定要删除特殊号码【${row.phoneNumber}】吗?`, '提示', {
  141. confirmButtonText: '确认',
  142. cancelButtonText: '取消',
  143. type: 'warning',
  144. draggable: true,
  145. cancelButtonClass: 'default-button',
  146. autofocus: false,
  147. })
  148. .then(() => {
  149. deleteSpecialNumber({ id: row.id }).then(() => {
  150. ElMessage.success('操作成功');
  151. queryList();
  152. });
  153. })
  154. .catch(() => {});
  155. };
  156. const tableRef = ref<RefType>();
  157. const toolbarRef = ref<RefType>();
  158. // 页面加载时
  159. onMounted(() => {
  160. queryList();
  161. if (tableRef.value && toolbarRef.value) {
  162. tableRef.value.connect(toolbarRef.value);
  163. }
  164. });
  165. </script>