list.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <script setup lang="ts">
  2. import FormSearch, { type FormField } from "@/components/opts/form-search.vue";
  3. import TableButtons from "@/components/opts/btns2.vue";
  4. import Edit from "./edit.vue";
  5. import { PureTable } from "@pureadmin/table";
  6. import { computed, onBeforeMount, onMounted, reactive, ref, watch } from "vue";
  7. import * as $api from "@/api/agent/index";
  8. import { hasAuth } from "@/router/utils";
  9. import message from "@/utils/message";
  10. import { enableOptions } from "@/constants/constants";
  11. import { cloneDeep } from "@pureadmin/utils";
  12. const editRef = ref();
  13. defineOptions({
  14. name: "agentList"
  15. });
  16. const props: any = defineProps({
  17. mode: {
  18. required: false,
  19. type: String,
  20. default: "table"
  21. }
  22. });
  23. const searchFormFields = computed((): FormField[] => {
  24. const fields: FormField[] = [
  25. {
  26. type: "input",
  27. label: "代理商名称",
  28. prop: "agentname",
  29. placeholder: "请输入代理商名模糊查询"
  30. },
  31. {
  32. type: "select",
  33. label: "状态",
  34. prop: "status",
  35. placeholder: "请选择",
  36. dataSourceKey: "enableOptions",
  37. options: {
  38. keys: {
  39. label: "label",
  40. value: "value",
  41. prop: "value"
  42. },
  43. filterable: true
  44. }
  45. }
  46. ];
  47. if (props.mode === "table") {
  48. return fields;
  49. } else {
  50. return fields;
  51. }
  52. });
  53. const pageData: any = reactive({
  54. mode: "table",
  55. permission: {
  56. query: ["user:query"],
  57. save: ["user:save"],
  58. update: ["user:update"],
  59. del: ["user:del"]
  60. },
  61. searchParam: {
  62. searchState: true,
  63. searchForm: {}
  64. },
  65. dataSource: {
  66. enableOptions: enableOptions
  67. },
  68. /*按钮 */
  69. btnOpts: {
  70. size: "small",
  71. leftBtns: [
  72. {
  73. key: "add",
  74. label: "新增",
  75. type: "primary",
  76. icon: "ep:plus",
  77. state: true,
  78. permission: ["user:save"]
  79. }
  80. ],
  81. rightBtns: [
  82. {
  83. key: "search",
  84. label: "查询",
  85. icon: "ep:search",
  86. state: true,
  87. options: {
  88. circle: true
  89. }
  90. },
  91. {
  92. key: "refresh",
  93. label: "刷新",
  94. icon: "ep:refresh",
  95. state: true,
  96. options: {
  97. circle: true
  98. }
  99. }
  100. ]
  101. },
  102. tableParam: {
  103. list: [],
  104. columns: [
  105. {
  106. label: "ID",
  107. prop: "id",
  108. slot: "id",
  109. width: 220
  110. },
  111. {
  112. label: "代理商名称",
  113. prop: "userName",
  114. slot: "userName"
  115. },
  116. {
  117. label: "余额",
  118. prop: "amount",
  119. slot: "amount"
  120. },
  121. {
  122. label: "谷歌校验器",
  123. prop: "hasTpop",
  124. slot: "hasTpop"
  125. },
  126. {
  127. label: "状态",
  128. prop: "status",
  129. slot: "status"
  130. },
  131. {
  132. label: "更新时间",
  133. prop: "updateTime",
  134. slot: "updateTime"
  135. },
  136. {
  137. label: "操作",
  138. fixed: "right",
  139. slot: "operation"
  140. }
  141. ],
  142. loading: false,
  143. pagination: {
  144. small: true,
  145. pageSize: 10,
  146. defaultPageSize: 10,
  147. currentPage: 1,
  148. background: true,
  149. total: 0
  150. }
  151. }
  152. });
  153. const btnClickHandle = (val: string) => {
  154. switch (val) {
  155. case "add":
  156. editRef.value!.open({ enable: 1 }, pageData.dataSource, "add");
  157. break;
  158. case "update":
  159. break;
  160. case "search":
  161. _updateSearchState();
  162. break;
  163. case "refresh":
  164. _loadData();
  165. break;
  166. case "switch":
  167. break;
  168. default:
  169. break;
  170. }
  171. };
  172. /**
  173. * 更新搜索表单
  174. * @param data .
  175. */
  176. const _updateSearchFormData = (data: any) => {
  177. pageData.searchParam.searchForm = data;
  178. };
  179. /**
  180. * 点击搜索按钮
  181. */
  182. const _searchForm = (data: any) => {
  183. pageData.searchParam.searchForm = data;
  184. _loadData();
  185. };
  186. /**
  187. * 重置
  188. */
  189. const _resetSearchForm = (data?: any) => {
  190. pageData.searchParam.searchForm = data;
  191. };
  192. /**
  193. * 更新搜索表达的状态
  194. */
  195. const _updateSearchState = () => {
  196. pageData.searchParam.searchState = !pageData.searchParam.searchState;
  197. };
  198. /**
  199. * 分页 - 改变每页条数
  200. * @param val .
  201. */
  202. const handleChangePageSize = (val: any) => {
  203. pageData.tableParam.pagination.pageSize = val;
  204. _loadData();
  205. };
  206. /**
  207. * 分页 - 改变页码
  208. * @param val .
  209. */
  210. const handleChangeCurrentPage = (val: any) => {
  211. pageData.tableParam.pagination.currentPage = val;
  212. _loadData();
  213. };
  214. /**
  215. * 获取查询参数
  216. */
  217. const getQueryParams = () => {
  218. const sqp = {};
  219. const param = Object.assign(sqp, pageData.searchParam.searchForm);
  220. param.current = pageData.tableParam.pagination.currentPage;
  221. param.size = pageData.tableParam.pagination.pageSize;
  222. return param;
  223. };
  224. /**
  225. * 获取列表数据
  226. * @param page .
  227. */
  228. const _loadData = (page?: number) => {
  229. const query = getQueryParams();
  230. if (page) {
  231. query.current = page;
  232. }
  233. pageData.tableParam.loading = true;
  234. $api
  235. .queryPage(query)
  236. .then((res: any) => {
  237. if (res.success) {
  238. pageData.tableParam.list = res.result.records;
  239. pageData.tableParam.pagination.total = Number(res.result.total);
  240. }
  241. })
  242. .finally(() => {
  243. pageData.tableParam.loading = false;
  244. });
  245. };
  246. /**
  247. * 查看详情
  248. * @param row .
  249. */
  250. const handleDetail = (row: any) => {
  251. editRef.value!.open(cloneDeep(row), pageData.dataSource, "detail");
  252. };
  253. /**
  254. * 编辑
  255. * @param row .
  256. */
  257. const handleEdit = (row: any) => {
  258. editRef.value!.open(cloneDeep(row), pageData.dataSource, "edit");
  259. };
  260. /**
  261. * 删除
  262. * @param row .
  263. */
  264. const handleDel = (row: any) => {
  265. message.confirm(`确认删除 id 为 (${row.id}) 的数据?`).then(() => {
  266. batchDel([row.id]);
  267. });
  268. };
  269. /**
  270. * 批量删除
  271. * @param ids .
  272. */
  273. const batchDel = (ids: string[]) => {
  274. if (ids && ids.length > 0) {
  275. $api.del(ids).then((res: any) => {
  276. if (res.success) {
  277. message.success("删除成功");
  278. _loadData();
  279. } else {
  280. message.warning(res.message);
  281. }
  282. });
  283. }
  284. };
  285. watch(
  286. () => props.orgInfo,
  287. val => {
  288. if (val) {
  289. _loadData();
  290. }
  291. }
  292. );
  293. onBeforeMount(() => {});
  294. onMounted(() => {
  295. _loadData(1);
  296. });
  297. </script>
  298. <template>
  299. <div>
  300. <form-search
  301. size="small"
  302. :show="pageData.searchParam.searchState"
  303. :form-field="searchFormFields"
  304. :data-source="pageData.dataSource"
  305. :query-permission="pageData.permission.query"
  306. @search-form="_updateSearchFormData"
  307. @search="_searchForm"
  308. @reset="_resetSearchForm"
  309. />
  310. <!--operate-->
  311. <table-buttons
  312. :size="pageData.btnOpts.size"
  313. :left-btns="pageData.btnOpts.leftBtns"
  314. :right-btns="pageData.btnOpts.rightBtns"
  315. @click="btnClickHandle"
  316. />
  317. <!--table-->
  318. <pure-table
  319. :data="pageData.tableParam.list"
  320. :columns="pageData.tableParam.columns"
  321. row-key="id"
  322. size="small"
  323. border
  324. stripe
  325. :header-row-class-name="'table-header'"
  326. :loading="pageData.tableParam.loading"
  327. :pagination="pageData.tableParam.pagination"
  328. @page-current-change="handleChangeCurrentPage"
  329. @page-size-change="handleChangePageSize"
  330. >
  331. <template #ellipsis="{ row, column }">
  332. <el-tooltip placement="top-start" :content="row[column.property]"
  333. >{{ row[column.property] }}
  334. </el-tooltip>
  335. </template>
  336. <template #enableScope="scope">
  337. <el-tag v-if="scope.row.enable">启用</el-tag>
  338. <el-tag v-else type="info">禁用</el-tag>
  339. </template>
  340. <template #operation="{ row }">
  341. <div class="flex justify-center items-center">
  342. <el-link
  343. v-show="hasAuth(pageData.permission.update)"
  344. type="primary"
  345. @click="handleEdit(row)"
  346. >编辑
  347. </el-link>
  348. <el-divider
  349. v-show="hasAuth(pageData.permission.del)"
  350. direction="vertical"
  351. />
  352. <el-link
  353. v-show="hasAuth(pageData.permission.del)"
  354. type="primary"
  355. @click="handleDel(row)"
  356. >删除
  357. </el-link>
  358. </div>
  359. </template>
  360. </pure-table>
  361. <edit ref="editRef" @ok="_loadData" />
  362. </div>
  363. </template>