list.vue 9.2 KB

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