list.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="p-4">
  3. <BasicTable @register="registerTable">
  4. <template #toolbar>
  5. <a-button
  6. v-power="[RoleEnum.COMPANY_ADMIN, RoleEnum.PLAT_ADMIN]"
  7. type="primary"
  8. @click="handleCreate"
  9. >新增</a-button
  10. >
  11. </template>
  12. <template #headerTop v-if="getCheckRole([RoleEnum.COMPANY_ADMIN])">
  13. <Alert
  14. :message="`剩余带看权益为 ${surplusSubNum.lookNum} 个、拍摄权益为 ${surplusSubNum.shotNum} 个`"
  15. type="info"
  16. />
  17. </template>
  18. <template #role="{ record }">
  19. {{ renderRoleType(record.role) }}
  20. </template>
  21. <template #status="{ record }">
  22. {{ renderStatus(record.status) }}
  23. </template>
  24. <template #createTime="{ record }">
  25. <Time :value="record.createTime" mode="datetime" />
  26. </template>
  27. <!-- , -->
  28. <template #action="{ record }">
  29. <TableAction
  30. :actions="[
  31. {
  32. label: '编辑',
  33. onClick: handleEdit.bind(null, record),
  34. },
  35. {
  36. color: 'warning',
  37. label: t('routes.staff.setpaswd'),
  38. onClick: handleOpenModal.bind(null, record),
  39. },
  40. {
  41. label: '删除',
  42. color: 'error',
  43. popConfirm: {
  44. title: '是否确认删除',
  45. confirm: handleDelete.bind(null, record),
  46. },
  47. },
  48. ]"
  49. />
  50. </template>
  51. </BasicTable>
  52. <DetailsModal @register="registerDetail" @ok="reload" />
  53. <SetpaswordModal @register="register" @reload="reload" />
  54. <DelListModal @register="registerDelList" @reload="reload" />
  55. </div>
  56. </template>
  57. <script lang="ts">
  58. import { defineComponent, computed, onMounted, ref } from 'vue';
  59. import { BasicTable, useTable, BasicColumn, FormProps, TableAction } from '/@/components/Table';
  60. import { useMessage } from '/@/hooks/web/useMessage';
  61. import { useModal } from '/@/components/Modal';
  62. import { uploadApi } from '/@/api/sys/upload';
  63. import SetpaswordModal from './setpaswordModal.vue';
  64. import DetailsModal from './detailsModal.vue';
  65. import DelListModal from './delListModal.vue';
  66. import { Alert } from 'ant-design-vue';
  67. // import { h } from 'vue';
  68. import { ListApi, delApi, preDelApi, getNumByStaff } from '/@/api/staff/list';
  69. import { useI18n } from '/@/hooks/web/useI18n';
  70. // import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
  71. import { RoleEnum } from '/@/enums/roleEnum';
  72. import { useGo } from '/@/hooks/web/usePage';
  73. import { Time } from '/@/components/Time';
  74. import { useUserStore } from '/@/store/modules/user';
  75. export default defineComponent({
  76. components: {
  77. BasicTable,
  78. TableAction,
  79. Time,
  80. SetpaswordModal,
  81. DetailsModal,
  82. DelListModal,
  83. Alert,
  84. },
  85. setup() {
  86. const [register, { openModal }] = useModal();
  87. const surplusSubNum = ref({
  88. lookNum: 0,
  89. shotNum: 0,
  90. });
  91. const [registerDetail, { openModal: openDetaileModal }] = useModal();
  92. const [registerDelList, { openModal: openDelListeModal }] = useModal();
  93. const { createConfirm, createMessage } = useMessage();
  94. const userStore = useUserStore();
  95. const { getCheckRole } = userStore;
  96. const roleList = computed(() => userStore.getRoleList);
  97. console.log('getRoleList', roleList);
  98. const go = useGo();
  99. const { t } = useI18n();
  100. onMounted(() => {
  101. getNumByStaffData();
  102. });
  103. const columns: BasicColumn[] = [
  104. {
  105. title: 'ID',
  106. dataIndex: 'id',
  107. fixed: 'left',
  108. width: 60,
  109. },
  110. {
  111. title: t('routes.staff.deptName'),
  112. dataIndex: 'companyName',
  113. width: 160,
  114. },
  115. // {
  116. // title: t('routes.staff.userName'),
  117. // dataIndex: 'userName',
  118. // width: 80,
  119. // },
  120. {
  121. title: t('routes.staff.userName'),
  122. dataIndex: 'nickName',
  123. width: 80,
  124. },
  125. {
  126. title: '手机',
  127. dataIndex: 'phone',
  128. width: 160,
  129. },
  130. {
  131. title: t('common.roleName'),
  132. dataIndex: 'roleName',
  133. // slots: { customRender: 'role' },
  134. sorter: true,
  135. width: 80,
  136. },
  137. // {
  138. // title: t('common.state'),
  139. // dataIndex: 'status',
  140. // slots: { customRender: 'status' },
  141. // // sorter: true,
  142. // width: 80,
  143. // },
  144. {
  145. title: t('routes.staff.createTime'),
  146. dataIndex: 'createTime',
  147. slots: { customRender: 'createTime' },
  148. width: 130,
  149. },
  150. {
  151. title: '操作',
  152. dataIndex: '',
  153. ifShow: !getCheckRole('tourist'),
  154. slots: { customRender: 'action' },
  155. fixed: 'right',
  156. width: 150,
  157. },
  158. ];
  159. const searchForm: Partial<FormProps> = {
  160. labelWidth: 100,
  161. schemas: [
  162. {
  163. field: 'staffName',
  164. label: t('routes.corporation.phone'),
  165. component: 'Input',
  166. componentProps: {
  167. maxLength: 15,
  168. },
  169. colProps: {
  170. xl: 5,
  171. xxl: 5,
  172. },
  173. },
  174. ],
  175. };
  176. const [registerTable, { reload }] = useTable({
  177. title: t('routes.staff.staffList'),
  178. api: ListApi,
  179. columns: columns,
  180. useSearchForm: true,
  181. formConfig: searchForm,
  182. showTableSetting: true,
  183. tableSetting: { fullScreen: true },
  184. showIndexColumn: false,
  185. rowKey: 'id',
  186. pagination: { pageSize: 20 },
  187. afterFetch: (T) => {
  188. getNumByStaffData();
  189. return T;
  190. },
  191. bordered: true,
  192. sortFn: (sortInfo) => {
  193. let order = sortInfo.order && sortInfo.order.replace('end', '');
  194. return { ...sortInfo, sidx: sortInfo.field, order: order };
  195. },
  196. });
  197. function renderRoleType(type: number): string {
  198. switch (type) {
  199. case 0:
  200. return t('routes.staff.roleType.0');
  201. case 1:
  202. return t('routes.staff.roleType.1');
  203. default:
  204. return '';
  205. }
  206. }
  207. function renderStatus(type: number): string {
  208. switch (type) {
  209. case 1:
  210. return t('common.normal');
  211. case 0:
  212. return t('common.unNormal');
  213. default:
  214. return '';
  215. }
  216. }
  217. function handleOpenModal(record: Recordable) {
  218. openModal(true, record);
  219. }
  220. function handleCreate() {
  221. if (
  222. getCheckRole([RoleEnum.COMPANY_ADMIN]) &&
  223. surplusSubNum.value.lookNum == 0 &&
  224. surplusSubNum.value.shotNum == 0
  225. ) {
  226. return createMessage.error('新增失败,可添加员工数量为0个');
  227. }
  228. openDetaileModal(true, {});
  229. }
  230. function handleEdit(record: Recordable) {
  231. openDetaileModal(true, record);
  232. }
  233. function getNumByStaffData() {
  234. getNumByStaff({}).then((res) => {
  235. surplusSubNum.value.lookNum = res.lookNum;
  236. surplusSubNum.value.shotNum = res.shotNum;
  237. });
  238. }
  239. async function handleDelete(record) {
  240. let check = await preDelApi(record.id); //
  241. if (Array.isArray(check)) {
  242. return openDelListeModal(true, {
  243. ...record,
  244. option: check,
  245. });
  246. }
  247. createMessage.success(t('common.optSuccess'));
  248. reload();
  249. // handDelconfirm(record);
  250. }
  251. function handDelconfirm(record) {
  252. createConfirm({
  253. iconType: 'warning',
  254. title: '警告',
  255. content: `此操作将对${record.userName}进行删除, 是否继续?`,
  256. onOk: async () => {
  257. await delApi({ userId: record.id });
  258. reload();
  259. },
  260. });
  261. }
  262. return {
  263. registerTable,
  264. registerDetail,
  265. registerDelList,
  266. openDelListeModal,
  267. createMessage,
  268. handDelconfirm,
  269. t,
  270. reload,
  271. go,
  272. renderRoleType,
  273. renderStatus,
  274. handleCreate,
  275. handleOpenModal,
  276. register,
  277. handleEdit,
  278. handleDelete,
  279. uploadApi: uploadApi as any,
  280. RoleEnum,
  281. surplusSubNum,
  282. getCheckRole,
  283. getNumByStaffData,
  284. };
  285. },
  286. });
  287. </script>