index.vue 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. <template>
  2. <div class="h-full flex flex-col teamstyle overflow-hidden temaClass">
  3. <!-- 头部 -->
  4. <div class="bg-white flex justify-between team-header">
  5. <div class="flex items-center">
  6. <el-link type="primary" class="text-nowrap mr-20" :icon="CirclePlusFilled"
  7. @click="dialogFromCli('addDeptDialogVisible')">创建部门</el-link>
  8. <el-link class="text-nowrap textFont textFont mr-10" type="primary" :icon="Edit"
  9. @click="updateDepartment('addDeptDialogVisible')">
  10. <template v-if="!deptListItem.labe">全部人员</template>
  11. <template v-if="deptListItem.labe">
  12. <TextTranslation translationTypes="departmentName" :translationValue="deptListItem.labe"></TextTranslation>
  13. </template>
  14. </el-link>
  15. <span class="textSpan textFont">共 0 人</span>
  16. </div>
  17. <div class="teamForm flex items-center">
  18. <el-input v-model="teamForm.keyword" style="max-width: 650px" size="default" placeholder="请输入姓名搜索" class="mr-6"
  19. clearable @clear="getTableData()" @keyup.enter.native="getTableData()">
  20. <template #prepend>
  21. <el-select v-model="teamForm.matchingType" style="width: 80px">
  22. <el-option label="姓名" :value="0" />
  23. <el-option label="电话" :value="1" />
  24. <el-option label="工号" :value="2" />
  25. </el-select>
  26. </template>
  27. <template #append>
  28. <el-button :icon="Search" @click="getTableData()" />
  29. </template>
  30. </el-input>
  31. <div class="formItem mr-6 flex items-center">
  32. <div class="text-nowrap">状态:</div>
  33. <el-select v-model="teamForm.status" placeholder="请选择" size="default" style="width: 100px"
  34. @change="getTableData()">
  35. <el-option v-for="item in stateOptions" :key="item.value" :label="item.label" :value="item.value" />
  36. </el-select>
  37. </div>
  38. <div class="formItem mr-6 flex items-center">
  39. <div class="text-nowrap">角色:</div>
  40. <el-select v-model="teamForm.roleId" placeholder="请选择" size="default" style="width: 150px" clearable
  41. @change="getTableData()">
  42. <el-option v-for="item in roleList" :key="item.id" :label="item.rolename" :value="item.id" />
  43. </el-select>
  44. </div>
  45. <el-button type="primary" v-if="userInfo.userNameNeedTranslate == 1"
  46. @click="transitionOperation('exportUser', '')" v-permission="['teamExport']">导出人员</el-button>
  47. <el-button type="primary" v-if="userInfo.userNameNeedTranslate == 1"
  48. @click="dialogFrom.newSyncWithCorpWxDayloadVisable = true">同步企微通讯录</el-button>
  49. <el-dropdown v-if="userInfo.userNameNeedTranslate != 1">
  50. <el-button type="primary">
  51. 更多操作<el-icon class="el-icon--right"><arrow-down /></el-icon>
  52. </el-button>
  53. <template #dropdown>
  54. <el-dropdown-menu>
  55. <el-dropdown-item @click="addPersone(false)" v-permission="['teamAdd']">添加人员</el-dropdown-item>
  56. <el-dropdown-item @click="transitionOperation('exportUser', '')"
  57. v-permission="['teamExport']">导出人员</el-dropdown-item>
  58. <el-dropdown-item @click="transitionOperation('importUser', '')"
  59. v-permission="['teamImport']">批量导入</el-dropdown-item>
  60. <el-dropdown-item @click="officialAccountSetting()">
  61. {{ officialAccountInformation.id ? '修改公众号配置' : '配置公众号' }}
  62. </el-dropdown-item>
  63. <el-dropdown-item @click="oneClickGenerationOfQrCode()" v-if="officialAccountInformation.id">
  64. 一键生成员工二维码
  65. </el-dropdown-item>
  66. <el-dropdown-item @click="exportQrCode()" v-if="officialAccountInformation.id">
  67. 导出员工二维码
  68. </el-dropdown-item>
  69. </el-dropdown-menu>
  70. </template>
  71. </el-dropdown>
  72. </div>
  73. </div>
  74. <!-- 内容 -->
  75. <div class="flex-1 flex">
  76. <div class="p-4 w-80 pr-0">
  77. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col">
  78. <div class="flex-1 overflow-y-auto const-left">
  79. <el-tree style="max-width: 600px" :data="deptList" :props="treeProps" @node-click="treeNode">
  80. <template #default="{ node, data }">
  81. <div class="flex justify-between treeContent">
  82. <div class="custom-tree-node" @mouseleave="mouseleave(data, $event)"
  83. @mouseover="mouseover(data, $event)">
  84. <div class="treeLabel">
  85. <TextTranslation translationTypes="departmentName" :translationValue="node.label">
  86. </TextTranslation>
  87. </div>
  88. <div class="treeIcon nodeEle" id="treeIcon" v-if="data.id > 0">
  89. <el-link type="primary" :icon="CirclePlus" :underline="false"
  90. @click.stop="dialogFromCli('addDeptDialogVisible', data, true)"></el-link>
  91. <el-link type="primary" :icon="Delete" :underline="false" style="margin-left: 6px;"
  92. @click.stop="deteleDept(data)"></el-link>
  93. </div>
  94. </div>
  95. </div>
  96. </template>
  97. </el-tree>
  98. </div>
  99. </div>
  100. </div>
  101. <div class="flex-1 p-4 overflow-auto">
  102. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col overflow-hidden pt-2 pl-2 pr-2">
  103. <div class="flex-1">
  104. <el-table ref="multipleTableRef" :data="tableData" v-loading="loadingFrom.tableLoading"
  105. @selection-change="changeBatch" style="width: 100%;height: calc(100vh - 204px);">
  106. <el-table-column type="selection" width="55" />
  107. <el-table-column label="姓名" property="name" width="150">
  108. <template #default="scope">
  109. <div class="flex items-center">
  110. <TextTranslation translationTypes="userName" :translationValue="scope.row.name"></TextTranslation>
  111. <template v-if="officialAccountInformation.id && scope.row.wxImgUrlWithTicket">
  112. <el-tooltip class="box-item" effect="dark" content="点击查看销售二维码" placement="top">
  113. <div class="ml-2 cursor-pointer" @click="viewQrCode(scope.row)">
  114. <el-icon color="#075985">
  115. <PictureFilled />
  116. </el-icon>
  117. </div>
  118. </el-tooltip>
  119. </template>
  120. </div>
  121. </template>
  122. </el-table-column>
  123. <el-table-column label="手机" property="phone"></el-table-column>
  124. <el-table-column label="工号" property="jobNumber"></el-table-column>
  125. <el-table-column label="部门" property="departmentName">
  126. <template #default="scope">
  127. <TextTranslation translationTypes="departmentName" :translationValue="scope.row.departmentName">
  128. </TextTranslation>
  129. </template>
  130. </el-table-column>
  131. <el-table-column label="角色" property="roleName"></el-table-column>
  132. <el-table-column label="创建时间" property="createTime"></el-table-column>
  133. <el-table-column label="操作" width="200" fixed="right">
  134. <template #default="scope">
  135. <el-button :size="'small'" @click="resetPwd(scope.row)">重置</el-button>
  136. <el-button type="primary" :size="'small'" @click="addPersone(scope.row)">编辑</el-button>
  137. <el-button :size="'small'" @click="transitionOperation('disable', scope.row)"
  138. v-if="scope.row.isActive == 1">停用</el-button>
  139. <el-button type="success" :size="'small'" @click="enableUser(scope.row)"
  140. v-if="scope.row.isActive == 0">启用</el-button>
  141. </template>
  142. </el-table-column>
  143. </el-table>
  144. </div>
  145. <div class="flex justify-between pb-2 pt-2 pl-3 pr-3">
  146. <div class="flex">
  147. <el-button size="default" @click="changeBatch(false)"
  148. :disabled="batchTableData.length == 0">取消</el-button>
  149. <el-dropdown class="ml-3">
  150. <el-button type="primary">
  151. 更多操作<el-icon class="el-icon--right"><arrow-down /></el-icon>
  152. </el-button>
  153. <template #dropdown>
  154. <el-dropdown-menu>
  155. <el-dropdown-item @click="batchItem('批量修改部门', 'dept', deptList)"
  156. :disabled="batchTableData.length == 0">批量修改部门</el-dropdown-item>
  157. <el-dropdown-item @click="batchItem('批量修改角色', 'role', roleList)"
  158. :disabled="batchTableData.length == 0">批量修改角色</el-dropdown-item>
  159. <el-dropdown-item @click="batchEnableItem"
  160. :disabled="batchTableData.length == 0">批量启用员工</el-dropdown-item>
  161. </el-dropdown-menu>
  162. </template>
  163. </el-dropdown>
  164. </div>
  165. <div class="pr-4">
  166. <el-pagination layout="total, prev, pager, next, sizes" :total="totalTable" :page-size="teamForm.pageSize"
  167. @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  168. </div>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. <!-- 新增部门 -->
  174. <el-dialog v-model="dialogFrom.addDeptDialogVisible" width="600" :show-close="false" :before-close="handleClose">
  175. <template #header="{ close, titleId, titleClass }">
  176. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  177. <h4 :id="titleId">{{ deptListItem.label || '创建部门' }}</h4>
  178. <div class="flex">
  179. <el-button @click="dialogFrom.addDeptDialogVisible = false">取消</el-button>
  180. <el-button type="primary" @click="createDepartment(deptRuleFormRef)"
  181. v-bind:loading="loadingFrom.deptDialogVisibleLoading">
  182. 确定
  183. </el-button>
  184. </div>
  185. </div>
  186. </template>
  187. <div class="pt-5">
  188. <el-form ref="deptRuleFormRef" style="max-width: 500px" :model="deptForm" :rules="deptRules" label-width="140px"
  189. size="large" status-icon>
  190. <el-form-item label="部门名称" prop="name">
  191. <el-input v-model="deptForm.name" placeholder="请输入部门名称" clearable
  192. :disabled="userInfo.userNameNeedTranslate == 1" />
  193. </el-form-item>
  194. <el-form-item label="主要负责人">
  195. <!-- <el-select v-model="deptForm.managerId" placeholder="请选择" style="width: 100%" clearable>
  196. <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id" />
  197. </el-select> -->
  198. <personnel-search v-model="deptForm.managerId" :size="''" placeholder="请选择"></personnel-search>
  199. </el-form-item>
  200. <el-form-item label="其他负责人">
  201. <!-- <el-select v-model="deptForm.otherManagerIds" placeholder="请选择" style="width: 100%" multiple clearable>
  202. <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id" />
  203. </el-select> -->
  204. <personnel-search v-model="deptForm.otherManagerIds" :size="''" multiple
  205. placeholder="请选择"></personnel-search>
  206. </el-form-item>
  207. </el-form>
  208. </div>
  209. </el-dialog>
  210. <!-- 停用 -->
  211. <el-dialog v-model="dialogFrom.resignationVisible" width="600" :show-close="false" :before-close="handleClose">
  212. <template #header="{ close, titleId, titleClass }">
  213. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  214. <h4 :id="titleId">离职停用员工</h4>
  215. <div class="flex">
  216. <el-button @click="dialogFrom.resignationVisible = false">取消</el-button>
  217. <el-button type="primary" @click="resignation" v-bind:loading="loadingFrom.resignationLoading">
  218. 确定
  219. </el-button>
  220. </div>
  221. </div>
  222. </template>
  223. <div class="pt-4 pb-2">
  224. <div class="flex items-center justify-center">
  225. <div class="pr-2">员工离职日期:</div>
  226. <el-date-picker v-model="resignationDate" type="date" placeholder="请选择日期" value-format="YYYY-MM-DD"
  227. :clearable="false" />
  228. </div>
  229. </div>
  230. </el-dialog>
  231. <!-- 导出人员列表 -->
  232. <el-dialog v-model="dialogFrom.exportUserVisible" width="600" :show-close="false" :before-close="handleClose">
  233. <template #header="{ close, titleId, titleClass }">
  234. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  235. <h4 :id="titleId">导出人员列表</h4>
  236. <div class="flex">
  237. <el-button @click="dialogFrom.exportUserVisible = false">取消</el-button>
  238. <el-button type="primary" @click="exportUser" v-bind:loading="loadingFrom.exportUserLoading">
  239. 导出
  240. </el-button>
  241. </div>
  242. </div>
  243. </template>
  244. <div class="pt-4 pb-2">
  245. <div class="flex items-center justify-center">
  246. <div class="pr-2">导出:</div>
  247. <el-radio-group v-model="exportRadio" class="ml-4">
  248. <el-radio value="1" size="large">全部人员</el-radio>
  249. <el-radio value="0" size="large">仅在职人员</el-radio>
  250. </el-radio-group>
  251. </div>
  252. </div>
  253. </el-dialog>
  254. <!-- 人员导入 -->
  255. <el-dialog v-model="dialogFrom.importVisible" width="680" :show-close="false" top="10vh">
  256. <template #header="{ close, titleId, titleClass }">
  257. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  258. <h4 :id="titleId">人员批量导入</h4>
  259. <div class="flex">
  260. <el-button class="mr-3" @click="dialogFrom.importVisible = false">取消</el-button>
  261. <el-upload ref="importUserRef" class="upload-demo" :limit="1" :show-file-list="false" accept=".xlsx"
  262. :http-request="importUser">
  263. <el-button type="primary" :loading="loadingFrom.importLoading">导入</el-button>
  264. </el-upload>
  265. </div>
  266. </div>
  267. </template>
  268. <div class="p-8">
  269. <div class="ml-4 mr-4">
  270. <div class="flex items-center">1、点击下载 <el-link type="primary"
  271. @click="downloadFile('/upload/人员导入模板.xlsx', '人员导入模板.xlsx')">人员导入模板.xlsx</el-link></div>
  272. <div class="mt-4">2、填写excel模板,并上传</div>
  273. </div>
  274. </div>
  275. </el-dialog>
  276. <!-- 同步企业微信通讯录 -->
  277. <el-dialog v-model="dialogFrom.newSyncWithCorpWxDayloadVisable" width="600" :show-close="false"
  278. :before-close="handleClose">
  279. <template #header="{ close, titleId, titleClass }">
  280. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  281. <h4 :id="titleId">同步企微通讯录</h4>
  282. <div class="flex">
  283. <el-button @click="dialogFrom.newSyncWithCorpWxDayloadVisable = false">取消</el-button>
  284. <el-button type="primary" :loading="loadingFrom.newSyncWithCorpWxDayloadLoading"
  285. @click="newSyncWithCorpWx()">
  286. 开始同步
  287. </el-button>
  288. </div>
  289. </div>
  290. </template>
  291. <div class="pt-4 px-12 py-2">
  292. 同步前请联系企业微信管理员检查应用授权的可见范围路径:管理企业-应用管理-工时管家-可见范围
  293. </div>
  294. </el-dialog>
  295. <!-- 公众号配置 -->
  296. <el-dialog v-model="dialogFrom.officialAccountSettingVisable" width="600" :show-close="false"
  297. :before-close="handleClose" :close="closeOfficialAccountInformation(officialAccountInformationRef)">
  298. <template #header="{ close, titleId, titleClass }">
  299. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  300. <h4 :id="titleId">公众号配置</h4>
  301. <div class="flex">
  302. <el-button @click="dialogFrom.officialAccountSettingVisable = false">取消</el-button>
  303. <el-button type="primary" :loading="loadingFrom.officialAccountSettingLoading"
  304. @click="configureOfficialAccountInformation(officialAccountInformationRef)">
  305. 配置
  306. </el-button>
  307. </div>
  308. </div>
  309. </template>
  310. <div class="pt-4 px-12 py-2">
  311. <el-form ref="officialAccountInformationRef" style="max-width: 600px" :model="officialAccountInformationFrom"
  312. status-icon :rules="officialAccountInformationFromRules" label-width="auto" class="demo-ruleForm">
  313. <el-form-item label="名称:" prop="companyName">
  314. <el-input v-model.trim="officialAccountInformationFrom.companyName" placeholder="请输入" />
  315. </el-form-item>
  316. <el-form-item label="appId:" prop="appId">
  317. <el-input v-model.trim="officialAccountInformationFrom.appId" placeholder="请输入" />
  318. </el-form-item>
  319. <el-form-item label="appSecret:" prop="appSecret">
  320. <el-input v-model.trim="officialAccountInformationFrom.appSecret" placeholder="请输入" />
  321. </el-form-item>
  322. </el-form>
  323. <el-text class="mx-1" type="warning">请联系客服, 获取ip白名单参数, 配置后方可生效</el-text>
  324. </div>
  325. </el-dialog>
  326. <!-- 新增人员 -->
  327. <AddPersonnelModal :data="{
  328. addPersonnelDialogVisible: dialogFrom.addPersonnelDialogVisible,
  329. deptList: deptListUntreated,
  330. roleList: roleList,
  331. personnelFromData: personnelFromData
  332. }" @closeModal="closeModal" @personnelModalConfirm="personnelModalConfirm" />
  333. <!-- 批量操作 -->
  334. <BatchOperation :batchData="visibleData" :batchNode="batchTableData" :visibleText="allText.batchText"
  335. :popup="visibleType" :batchOperationVisible="dialogFrom.batchOperationVisible" @close="closeModal" />
  336. <!-- 图片预览 -->
  337. <el-image-viewer
  338. v-if="showPreview"
  339. :url-list="previewSrcList"
  340. show-progress
  341. :initial-index="0"
  342. @close="showPreview = false"
  343. />
  344. </div>
  345. </template>
  346. <script lang="ts" setup>
  347. import { ref, reactive, onMounted, onBeforeMount, inject } from 'vue';
  348. import { UploadRequestOptions, dayjs, ElLoading, ElNotification } from 'element-plus'
  349. import { Search, CirclePlusFilled, Edit, CirclePlus, Delete, PictureFilled } from '@element-plus/icons-vue'
  350. import { FormInstance, FormRules, ElMessageBox } from 'element-plus'
  351. import { useStore } from '@/store/index'
  352. import { GET_DATA_LIST, DETELE_DEPT, MOD, GET_USERINFO, GET_ROUTELIST, DEACTIVEUSER, SETACTIVE, GET_DEPTLIST, BACTHSERROLE, GET_USERLIST, GET_ADDDEPT, ADD_USER, SETRESETPWD, EXPOERTUSER, EDIT_ADDDEPT, GET_COMPANY_WEI_XIN, SAVE_OR_UPDATE, ONE_CLICK_GENERATION, EXPORT_QR_CODE } from './api'
  353. import { post, uploadFile, downloadFileRequest } from "@/utils/request";
  354. import { getFromValue, updateDepTreeData, resetFromValue, confirmAction, downloadFile } from '@/utils/tools'
  355. import { storeToRefs } from 'pinia';
  356. import personnelSearch from '@/components/translationComponent/personnelSearch/personnelSearch.vue';
  357. // 导入页面
  358. import AddPersonnelModal from './module/AddPersonnelModal.vue'
  359. import BatchOperation from './module/BatchOperation.vue'
  360. import { formatDate } from '@/utils/times';
  361. import { URL_IMPORTTHREAD } from '../thread/constant';
  362. const { getFunctionList, getUserInfoVal } = useStore()
  363. const { userInfo } = storeToRefs(useStore());
  364. const globalPopup = inject<GlobalPopup>('globalPopup')
  365. // 定义类型
  366. interface deptRuleForm { // 部门表单类型
  367. name: string,
  368. id: string | number,
  369. parentId: string | number,
  370. managerId: string | number,
  371. otherManagerIds: string[] | number[],
  372. }
  373. interface officialAccountInformationInterface { // 公众号类型
  374. id?: string | number,
  375. companyName: string,
  376. appId: string,
  377. appSecret: string,
  378. }
  379. // 固定数据
  380. const stateOptions = [{ value: '3', label: '全部' }, { value: '1', label: '在职' }, { value: '0', label: '停用' }]
  381. // ref
  382. const importUserRef = ref<any>()
  383. // 定义变量
  384. const transitiondata = ref<any>() // 过度数据(针对二次弹窗)
  385. const pagePermission: any = ref([]) // 功能权限
  386. const loadingFrom = reactive({ // 所有加载状态
  387. tableLoading: false,
  388. deptDialogVisibleLoading: false,
  389. resignationLoading: false,
  390. exportUserLoading: false,
  391. importLoading: false,
  392. newSyncWithCorpWxDayloadLoading: false,
  393. officialAccountSettingLoading: false,
  394. })
  395. const dialogFrom: any = reactive({ // 所有弹窗状态
  396. addDeptDialogVisible: false,
  397. addPersonnelDialogVisible: false,
  398. batchOperationVisible: false,
  399. resignationVisible: false,
  400. exportUserVisible: false,
  401. importVisible: false,
  402. newSyncWithCorpWxDayloadVisable: false,
  403. officialAccountSettingVisable: false,
  404. });
  405. const allText = reactive({
  406. batchText: '批量操作'
  407. })
  408. const visibleType = ref<batchOperationType>('dept') // 弹窗类型
  409. const visibleData = ref<any>([]) // 批量弹窗数据源
  410. const totalTable = ref(0) // 表格总数
  411. const tableData: any = ref([]) // 表格数据
  412. const roleList: any = ref([]) // 角色列表
  413. const userList: any = ref([]) // 用户列表
  414. const deptList: any = ref([]) // 部门数据
  415. const batchTableData: any = ref([]) // 批量数据
  416. const multipleTableRef: any = ref()
  417. const deptListUntreated: any = ref([]) // 部门数据(未处理)
  418. const deptListItem: any = ref({}) // 选中的部门数据
  419. const personnelFromData = ref({}) // 人员表单数据
  420. const resignationDate = ref(formatDate(new Date())) // 员工离职日期
  421. const exportRadio = ref('1') // 导出人员列表
  422. const teamForm = reactive({ // 筛选条件表单
  423. matchingType: 0,
  424. keyword: '',
  425. status: '3',
  426. pageIndex: 1,
  427. pageSize: 20,
  428. roleId: '',
  429. onlyDirect: '',
  430. departmentId: '-1',
  431. });
  432. const deptRuleFormRef = ref<FormInstance>() // 表单实例
  433. const deptForm = reactive<deptRuleForm>({ // 部门表单
  434. name: '',
  435. id: '',
  436. parentId: '',
  437. managerId: '',
  438. otherManagerIds: [],
  439. })
  440. const treeProps = { // 部门树配置
  441. children: 'children',
  442. label: 'label',
  443. }
  444. const officialAccountInformation = ref<officialAccountInformationInterface>({
  445. id: '',
  446. companyName: '',
  447. appId: '',
  448. appSecret: '',
  449. })
  450. const officialAccountInformationFrom = ref<officialAccountInformationInterface>({
  451. id: '',
  452. companyName: '',
  453. appId: '',
  454. appSecret: '',
  455. })
  456. const officialAccountInformationRef = ref<FormInstance>()
  457. const showPreview = ref(false)
  458. const previewSrcList = ref<string[]>([])
  459. // 定义校验规则
  460. const deptRules = reactive<FormRules<typeof deptForm>>({ // 部门表单校验规则
  461. name: [{ required: true, trigger: 'blur', message: '请输入部门名称' }]
  462. })
  463. const officialAccountInformationFromRules = reactive<FormRules<typeof officialAccountInformation>>({
  464. companyName: [{ required: true, trigger: 'blur', message: '请输入' }],
  465. appId: [{ required: true, trigger: 'blur', message: '请输入' }],
  466. appSecret: [{ required: true, trigger: 'blur', message: '请输入' }]
  467. })
  468. function viewQrCode(row: any) {
  469. const { wxImgUrlWithTicket = '' } = row
  470. previewSrcList.value = [wxImgUrlWithTicket]
  471. showPreview.value = true
  472. }
  473. function exportQrCode() {
  474. ElNotification({
  475. title: '提示',
  476. message: '二维码导出中...',
  477. type: 'info',
  478. showClose: false,
  479. duration: 0
  480. })
  481. downloadFileRequest(EXPORT_QR_CODE, {}).then((blob) => {
  482. const url = window.URL.createObjectURL(blob);
  483. const link = document.createElement('a');
  484. link.href = url;
  485. link.setAttribute('download', '员工销售二维码.zip'); // 根据需要设定文件名
  486. document.body.appendChild(link);
  487. link.click();
  488. link.remove();
  489. window.URL.revokeObjectURL(url);
  490. globalPopup?.showSuccess('下载中 请稍后')
  491. })
  492. }
  493. // 同步企业微信通讯录
  494. function newSyncWithCorpWx() {
  495. const loading = ElLoading.service({
  496. lock: true,
  497. text: 'Loading',
  498. background: 'rgba(0, 0, 0, 0.7)',
  499. })
  500. post(`/wxcorp/getCorpMembsFromPlatform`, { companyId: userInfo.value.companyId }).then(() => {
  501. globalPopup?.showSuccess('同步成功')
  502. dialogFrom.newSyncWithCorpWxDayloadVisable = false
  503. getRoleList()
  504. getUserList()
  505. getTableData()
  506. getDeptList()
  507. }).finally(() => {
  508. loading.close();
  509. })
  510. }
  511. // 定义方法
  512. async function importUser(param: UploadRequestOptions) {
  513. loadingFrom.importLoading = true
  514. const formData = new FormData();
  515. formData.append('file', param.file)
  516. const res = await uploadFile(URL_IMPORTTHREAD, formData).finally(() => {
  517. importUserRef.value.clearFiles()
  518. loadingFrom.importLoading = false
  519. })
  520. loadingFrom.importLoading = false
  521. if (res.code == 'ok') {
  522. globalPopup?.showSuccess('导入成功')
  523. closeModal('importVisible')
  524. getTableData()
  525. return
  526. }
  527. globalPopup?.showError(res.msg || '')
  528. }
  529. // 获取公众号配置信息
  530. function getCompanyWeiXin() {
  531. post(GET_COMPANY_WEI_XIN, {}).then((res) => {
  532. const { companyName = '', id = '', appId = '', appSecret = '' } = res.data
  533. officialAccountInformation.value = {
  534. id, companyName, appId, appSecret
  535. }
  536. })
  537. }
  538. function oneClickGenerationOfQrCode() {
  539. ElNotification({
  540. title: '提示',
  541. message: '生成二维码中...',
  542. type: 'info',
  543. showClose: false,
  544. duration: 0
  545. })
  546. post(ONE_CLICK_GENERATION, {}).then(() => {
  547. globalPopup?.showSuccess('生成成功')
  548. getTableData()
  549. })
  550. }
  551. async function configureOfficialAccountInformation(formEl: FormInstance | undefined) {
  552. if (!formEl) return
  553. await formEl.validate((valid) => {
  554. if (valid) {
  555. confirmAction('确定保存当前公众号的配置吗?', '公众号配置', 'warning').then(() => {
  556. loadingFrom.officialAccountSettingLoading = true
  557. post(SAVE_OR_UPDATE, getFromValue(officialAccountInformationFrom.value)).then(() => {
  558. globalPopup?.showSuccess('配置成功')
  559. closeModal('officialAccountSettingVisable')
  560. getCompanyWeiXin()
  561. }).finally(() => {
  562. loadingFrom.officialAccountSettingLoading = false
  563. })
  564. })
  565. }
  566. })
  567. }
  568. function closeOfficialAccountInformation(formEl: FormInstance | undefined) {
  569. if (!formEl) return
  570. formEl.resetFields()
  571. }
  572. function officialAccountSetting() {
  573. officialAccountInformationFrom.value = JSON.parse(JSON.stringify(officialAccountInformation.value))
  574. dialogFrom.officialAccountSettingVisable = true
  575. }
  576. function exportUser() {
  577. loadingFrom.exportUserLoading = true
  578. post(EXPOERTUSER, { containInvalid: exportRadio.value }).then((res) => {
  579. downloadFile(`${res.data}`, '人员列表.xlsx')
  580. globalPopup?.showSuccess('导出成功')
  581. closeModal('exportUserVisible')
  582. }).finally(() => {
  583. loadingFrom.exportUserLoading = false
  584. })
  585. }
  586. function enableUser(row: any) {
  587. const id = row.id
  588. post(SETACTIVE, { id, isActive: 1 }).then(() => {
  589. globalPopup?.showSuccess('启用成功')
  590. getTableData()
  591. })
  592. }
  593. function resignation() {
  594. const id = transitiondata.value.id || ''
  595. loadingFrom.resignationLoading = true
  596. post(DEACTIVEUSER, { id, inactiveDate: resignationDate.value }).then(() => {
  597. globalPopup?.showSuccess('停用成功')
  598. getTableData()
  599. closeModal('resignationVisible')
  600. }).finally(() => {
  601. loadingFrom.resignationLoading = false
  602. })
  603. }
  604. function resetPwd(row: any) {
  605. const userId = row.id
  606. confirmAction(`确定要为${row.name}重置密码吗?`, '重置密码').then(() => {
  607. post(SETRESETPWD, { userId }).then(() => {
  608. globalPopup?.showSuccess('密码已重置为000000,请通知员工及时修改')
  609. }).catch((err) => {
  610. globalPopup?.showError(err.msg)
  611. })
  612. })
  613. }
  614. function batchEnableItem() {
  615. const userIds = batchTableData.value.map((item: any) => item.id)
  616. post(BACTHSERROLE, { ids: JSON.stringify(userIds), isActive: 1 }).then(() => {
  617. globalPopup?.showSuccess('操作成功')
  618. changeBatch(false)
  619. getTableData()
  620. }).catch((err) => {
  621. globalPopup?.showError(err.msg)
  622. })
  623. }
  624. function changeBatch(flag: boolean = true) {
  625. if (flag) {
  626. batchTableData.value = multipleTableRef.value && multipleTableRef.value.getSelectionRows()
  627. } else {
  628. batchTableData.value = []
  629. multipleTableRef.value && multipleTableRef.value.clearSelection()
  630. }
  631. }
  632. function addPersone(item: any) {
  633. if (!item) {
  634. personnelFromData.value = {}
  635. dialogFrom.addPersonnelDialogVisible = true
  636. return
  637. }
  638. post(GET_USERINFO, { userId: item.id }).then(res => {
  639. const { id, name, phone, jobNumber, roleId, departmentCascade, departmentId, inductionDate } = res.data
  640. let newData = {
  641. id, name, phone, jobNumber, roleId,
  642. // departmentId: departmentCascade && departmentCascade.split(',').map(Number).reverse(),
  643. departmentId: departmentId,
  644. inductionDate
  645. }
  646. personnelFromData.value = newData
  647. dialogFrom.addPersonnelDialogVisible = true
  648. })
  649. }
  650. async function personnelModalConfirm(data: any, modelType: string) {
  651. post(ADD_USER, { ...data }).then(res => {
  652. if (res.code != 'ok') {
  653. dialogFrom[modelType] = false
  654. globalPopup?.showError(res.msg)
  655. return
  656. }
  657. dialogFrom[modelType] = false
  658. globalPopup?.showSuccess('添加成功')
  659. getTableData()
  660. }).catch(_err => {
  661. dialogFrom[modelType] = false
  662. })
  663. }
  664. function createDepartment(formEl: FormInstance | undefined) {
  665. if (!formEl) return
  666. let data = getFromValue(deptForm)
  667. loadingFrom.deptDialogVisibleLoading = true
  668. EDIT_ADDDEPT
  669. post(data.id ? EDIT_ADDDEPT : GET_ADDDEPT, { ...deptForm, otherManagerIds: data.otherManagerIds && data.otherManagerIds.join(',') }).then(res => {
  670. if (res.code != 'ok') {
  671. loadingFrom.deptDialogVisibleLoading = false
  672. globalPopup?.showError(res.msg)
  673. return
  674. }
  675. loadingFrom.deptDialogVisibleLoading = false
  676. globalPopup?.showSuccess(data.id ? '修改成功' : '创建成功')
  677. getDeptList()
  678. dialogFrom.addDeptDialogVisible = false
  679. }).catch(_err => {
  680. loadingFrom.deptDialogVisibleLoading = false
  681. })
  682. }
  683. function updateDepartment(type: string) {
  684. if (!deptListItem.value.id || deptListItem.value.id <= 0) return
  685. const { id, label, parentId, managerId, otherManagerIds } = deptListItem.value
  686. console.log(deptListItem.value)
  687. let data = { id, name: label, parentId, managerId, otherManagerIds }
  688. Object.assign(deptForm, data)
  689. dialogFrom[type] = true
  690. }
  691. function treeNode(item: any) {
  692. deptListItem.value = item
  693. teamForm.departmentId = item.id
  694. getTableData()
  695. }
  696. function deteleDept(data: any) {
  697. console.log(data)
  698. ElMessageBox.confirm(
  699. `确定删除【${data.label}】部门吗?`, '',
  700. {
  701. confirmButtonText: '确定',
  702. cancelButtonText: '取消',
  703. type: 'warning',
  704. }
  705. )
  706. .then(() => {
  707. post(DETELE_DEPT, { id: data.id }).then(res => {
  708. if (res.code != 'ok') {
  709. globalPopup?.showError(res.msg)
  710. return
  711. }
  712. globalPopup?.showSuccess('删除成功')
  713. getDeptList()
  714. })
  715. })
  716. }
  717. function getTableData() {
  718. loadingFrom.tableLoading = true
  719. post(GET_DATA_LIST, { ...teamForm }).then(res => {
  720. if (res.code != 'ok') {
  721. loadingFrom.tableLoading = false
  722. globalPopup?.showError(res.msg)
  723. return
  724. }
  725. loadingFrom.tableLoading = false
  726. totalTable.value = res.data.total
  727. tableData.value = res.data.records
  728. }).catch(_err => {
  729. loadingFrom.tableLoading = false
  730. })
  731. }
  732. function getRoleList() {
  733. const companyId = getUserInfoVal('companyId') || ''
  734. post(GET_ROUTELIST, { companyId }).then(res => {
  735. if (res.code != 'ok') {
  736. globalPopup?.showError(res.msg)
  737. return
  738. }
  739. roleList.value = res.data
  740. })
  741. }
  742. function getDeptList() {
  743. post(GET_DEPTLIST, {}).then(res => {
  744. if (res.code != 'ok') {
  745. globalPopup?.showError(res.msg)
  746. return
  747. }
  748. deptListUntreated.value = updateDepTreeData(res.data, false)
  749. deptList.value = updateDepTreeData(res.data, true)
  750. })
  751. }
  752. function getUserList() {
  753. post(GET_USERLIST, {}).then(res => {
  754. if (res.code != 'ok') {
  755. globalPopup?.showError(res.msg)
  756. return
  757. }
  758. userList.value = res.data
  759. })
  760. }
  761. function mouseleave(data: any, $event: Event) {
  762. if (data.id <= 0) return;
  763. const target = $event.currentTarget as HTMLElement;
  764. const iconElement = target.querySelector('#treeIcon');
  765. if (iconElement) {
  766. iconElement.setAttribute("class", "treeIcon nodeEle");
  767. }
  768. }
  769. function mouseover(data: any, $event: MouseEvent) {
  770. if (data.id <= 0) return;
  771. const target = $event.currentTarget as HTMLElement;
  772. const iconElement = target.querySelector('#treeIcon');
  773. if (iconElement) {
  774. iconElement.setAttribute("class", "treeIcon");
  775. }
  776. }
  777. function dialogFromCli(type: string, data: any = {}, flag: boolean = false) {
  778. resetDialog()
  779. if (flag) {
  780. const { id } = data
  781. deptForm.parentId = id
  782. }
  783. dialogFrom[type] = true
  784. }
  785. function handleSizeChange(val: number) {
  786. teamForm.pageIndex = 1
  787. teamForm.pageSize = val
  788. getTableData()
  789. }
  790. function handleCurrentChange(val: number) {
  791. teamForm.pageIndex = val
  792. getTableData()
  793. }
  794. function resetDialog() {
  795. let newDeptForm = resetFromValue(deptForm)
  796. Object.assign(deptForm, newDeptForm)
  797. }
  798. function batchItem(text: string, type: batchOperationType, data: any) {
  799. allText.batchText = text,
  800. visibleType.value = type
  801. visibleData.value = data
  802. dialogFrom.batchOperationVisible = true
  803. }
  804. function handleClose(done: any) {
  805. done()
  806. }
  807. function transitionOperation(type: string, data: any) {
  808. if (type == 'disable') { // 停用
  809. resignationDate.value = formatDate(new Date())
  810. console.log(resignationDate.value, '<==== 离职')
  811. dialogFrom.resignationVisible = true
  812. } else if (type == 'exportUser') { // 导出
  813. exportRadio.value = '1'
  814. dialogFrom.exportUserVisible = true
  815. } else if (type == 'importUser') { // 导入
  816. dialogFrom.importVisible = true
  817. }
  818. transitiondata.value = data
  819. }
  820. function closeModal(modelType: string, flag: boolean = false) {
  821. dialogFrom[modelType] = false
  822. if (flag) {
  823. changeBatch(false)
  824. getTableData()
  825. }
  826. }
  827. onBeforeMount(() => {
  828. pagePermission.value = getFunctionList(MOD)
  829. })
  830. onMounted(() => {
  831. getRoleList()
  832. getUserList()
  833. getTableData()
  834. getDeptList()
  835. getCompanyWeiXin()
  836. });
  837. </script>
  838. <style lang="scss" scoped>
  839. .teamstyle {
  840. .team-header {
  841. padding: 0.75rem 1.25rem;
  842. box-sizing: border-box
  843. }
  844. .textFont {
  845. font-size: 16px;
  846. }
  847. .textSpan {
  848. color: $fontGray;
  849. }
  850. }
  851. .const-left {
  852. padding: 0.75rem 0;
  853. .treeContent {
  854. width: 87%;
  855. .custom-tree-node {
  856. display: flex;
  857. align-items: center;
  858. justify-content: space-between;
  859. width: 100%;
  860. }
  861. .treeLabel {
  862. width: 80%;
  863. white-space: nowrap;
  864. overflow: hidden;
  865. text-overflow: ellipsis;
  866. }
  867. .treeIcon {
  868. display: flex;
  869. align-items: center;
  870. justify-self: flex-end;
  871. }
  872. .nodeEle {
  873. display: none;
  874. }
  875. }
  876. }
  877. .operation {
  878. cursor: pointer;
  879. }
  880. </style>
  881. <style>
  882. .temaClass .el-tree-node {
  883. padding: 4px 0;
  884. }
  885. </style>