index.vue 35 KB

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