list.vue 9.1 KB

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