index.vue 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. <template>
  2. <section>
  3. <el-col :span="4" class="left" :style="'height:'+ (tableHeight + 113) + 'px'">
  4. <div class="department">
  5. <span><i class="iconfont firerock-iconzuzhijiegou" style="font-size:10px;" ></i>&nbsp;部门</span>
  6. <div v-on:click="createDepartment(-1)">
  7. <i class="fa fa-plus-circle"></i>
  8. 创建
  9. </div>
  10. </div>
  11. <el-divider style="margin: 0px 0px !important;height:0.5px;"></el-divider>
  12. <div class="tree" :style="'height:'+ (tableHeight + 83) + 'px'">
  13. <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" accordion></el-tree>
  14. </div>
  15. </el-col>
  16. <el-col :span="20" class="right">
  17. <!--工具条-->
  18. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  19. <el-form :inline="true">
  20. <el-form-item>
  21. <div v-if="depData == null || depData.id == -1" class="nowTime" style="cursor:unset">
  22. <i class="fa fa-home"></i>全部人员
  23. </div>
  24. <div v-else-if="depData.id == 0" class="nowTime" style="cursor:unset">
  25. <i class="fa fa-home"></i>未分配
  26. </div>
  27. <div v-else-if="depData != null && depData.id != -1 && depData.id != 0" class="nowTime" @click="createDepartment(0)">
  28. <i class="fa fa-pencil-square-o"></i>
  29. {{depData!=null?depData.label:''}}
  30. </div>
  31. </el-form-item>
  32. <el-form-item>
  33. <div style="color:#999;font-size:13px;">共{{total}}人</div>
  34. </el-form-item>
  35. <el-form-item style="float:right;">
  36. <el-link type="primary" :underline="false" @click="showExportDialog">导出人员</el-link>
  37. </el-form-item>
  38. <el-form-item style="float:right;">
  39. <el-link type="primary" :underline="false" @click="openInsertDialog(null)">添加人员</el-link>
  40. </el-form-item>
  41. <el-form-item style="float:right;" v-if="depData != null && depData.id != -1 && depData.id != 0">
  42. <el-upload ref="upload" action="#" :limit="1" :http-request="importUser" :show-file-list="false">
  43. <el-link type="primary" :underline="false">批量导入</el-link>
  44. </el-upload>
  45. </el-form-item>
  46. <el-form-item style="float:right;">
  47. <el-link type="primary" :underline="false" href="./upload/人员导入模板.xlsx" download="人员导入模板.xlsx">模板下载</el-link>
  48. </el-form-item>
  49. <el-form-item v-if="depData != null && depData.id != -1 && depData.id != 0" style="float:right;border: 0.5px solid #20a0ff;height: 27px;margin-top: 6px;">
  50. </el-form-item>
  51. <el-form-item style="float:right;">
  52. <el-link type="danger" v-if="depData != null && depData.id != -1 && depData.id != 0" :underline="false" @click="deleteDep(null)">删除部门</el-link>
  53. </el-form-item>
  54. <el-form-item style="float:right;">
  55. <el-link type="primary" v-if="depData != null && depData.id != -1 && depData.id != 0" :underline="false" @click="createDepartment(-2)">新增子部门</el-link>
  56. </el-form-item>
  57. </el-form>
  58. </el-col>
  59. <!--列表-->
  60. <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
  61. <el-table-column type="index" width="50">
  62. <template slot-scope="scope" >
  63. {{scope.$index+1+(page-1)*size}}
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="name" label="姓名" sortable></el-table-column>
  67. <el-table-column prop="phone" label="手机" width="120"></el-table-column>
  68. <el-table-column prop="departmentName" label="部门" sortable></el-table-column>
  69. <el-table-column label="角色" width="100">
  70. <template slot-scope="scope">{{roleArray[scope.row.role]}}</template>
  71. </el-table-column>
  72. <el-table-column prop="monthCost" label="月成本" sortable>
  73. <template slot-scope="scope">{{scope.row.monthCost==null?0:scope.row.monthCost}} 元</template>
  74. </el-table-column>
  75. <el-table-column prop="cost" label="时薪" sortable>
  76. <template slot-scope="scope">{{scope.row.cost==null?0:scope.row.cost}} 元
  77. <el-link @click.native="showSalaryList(scope.row)"><i class="iconfont firerock-iconrecord"></i></el-link>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="操作" width="280">
  81. <template slot-scope="scope">
  82. <!-- <el-button size="small" v-if="scope.row.role == 0 && user.role == 1" @click="switchRole(scope.$index)">切换为管理员</el-button>
  83. <el-button size="small" v-if="scope.row.role == 2 && user.role == 1" @click="switchRole(scope.$index)">切换为员工</el-button> -->
  84. <el-button size="mini" type="default" v-if="scope.row.role == 1 && user.role == 1" @click="transferRole(scope.row)">转让</el-button>
  85. <el-button size="mini" type="default" v-if="scope.row.role != 1" @click="resetPwd(scope.row)">重置</el-button>
  86. <el-button size="mini" type="primary" v-if="scope.row.role != 1" @click="openInsertDialog(scope.$index)">编辑</el-button>
  87. <el-button size="mini" type="primary" v-if="scope.row.role == 1" @click="openInsertDialog1(scope.$index)">编辑</el-button>
  88. <el-button size="mini" type="default" v-if="scope.row.role != 1 && scope.row.isActive==1" @click="showDeactiveDialog(scope.row)">停用</el-button>
  89. <el-button size="mini" type="success" v-if="scope.row.role != 1 && scope.row.isActive==0" @click="setActive(scope.row, 1)">启用</el-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <!--工具条-->
  94. <el-col :span="24" class="toolbar">
  95. <el-pagination
  96. @size-change="handleSizeChange"
  97. @current-change="handleCurrentChange"
  98. :page-sizes="[20 , 50 , 80 , 100]"
  99. :page-size="size"
  100. layout="total, sizes, prev, pager, next"
  101. :total="total"
  102. style="float:right;"
  103. ></el-pagination>
  104. </el-col>
  105. </el-col>
  106. <!-- 新增部门 -->
  107. <el-dialog :title="depTitle" :visible.sync="departmentVisible" width="400px" >
  108. <el-form ref="depForm" :model="depForm" :rules="depRules" label-width="80px">
  109. <el-form-item label="部门名称" prop="name">
  110. <el-input v-model="depForm.name" placeholder="请输入部门名称" clearable></el-input>
  111. </el-form-item>
  112. <el-form-item label="负责人" prop="managerId">
  113. <el-select v-model="depForm.managerId" filterable clearable placeholder="请选择部门负责人" >
  114. <el-option v-for="item in users" :key="item.id" :label="item.name" :value="item.id"></el-option>
  115. </el-select>
  116. </el-form-item>
  117. </el-form>
  118. <span slot="footer" class="dialog-footer">
  119. <el-button @click="departmentVisible = false">取消</el-button>
  120. <el-button type="primary" @click="submitDepartment">提交</el-button>
  121. </span>
  122. </el-dialog>
  123. <!-- 新增单个人员的Dialog -->
  124. <el-dialog :title="title" :visible.sync="dialogVisible" width="550px" >
  125. <el-form ref="form1" :model="insertForm" :rules="rules" label-width="80px">
  126. <el-form-item label="名字" prop="name">
  127. <el-input v-model="insertForm.name" placeholder="请输入姓名" clearable></el-input>
  128. </el-form-item>
  129. <el-form-item label="电话" prop="phone">
  130. <el-input v-model="insertForm.phone" placeholder="请输入电话号码" clearable></el-input>
  131. </el-form-item>
  132. <el-form-item label="薪酬方式" prop="salaryType">
  133. <el-radio-group v-model="insertForm.salaryType" @change="onSalaryTypeChange">
  134. <el-radio :label="0" >固定月成本</el-radio>
  135. <el-radio :label="1">计时工资</el-radio>
  136. </el-radio-group>
  137. </el-form-item>
  138. <el-form-item label="月成本" prop="monthCost" v-if="insertForm.salaryType == 0">
  139. <el-input v-model="insertForm.monthCost" id="mc" @input="oninput" placeholder="请输入月成本,单位:元" clearable @keyup.native="restrictNumber('mc')"></el-input>
  140. <span style="color:orange;font-size:12px;">按照每个月工作{{timeType.monthDays}}天,每天{{timeType.allday}}小时预估时薪</span>
  141. <el-link :underline="false" style="color:blue;font-size:12px;margin-left:7px;" href="#/timetype">修改工作时长</el-link>
  142. </el-form-item>
  143. <el-form-item label="时薪" prop="cost">
  144. <el-input v-model="insertForm.cost" :disabled="insertForm.salaryType == 0" id="cc" style="width:120px;" @keyup.native="restrictNumber('cc')"
  145. placeholder="请输入成本 单位:元/小时" clearable></el-input>
  146. <span style="margin-left:25px;">生效日期</span>
  147. <el-date-picker v-model="insertForm.costApplyDate" value-format="yyyy-MM-dd"></el-date-picker>
  148. </el-form-item>
  149. <el-form-item label="部门" prop="departmentId">
  150. <el-cascader v-model="insertForm.departmentId" placeholder="请选择部门" style="width: 100%"
  151. :options="option" :props="{ checkStrictly: false,expandTrigger: 'hover' }" :show-all-levels="false" clearable></el-cascader>
  152. </el-form-item>
  153. <el-form-item label="角色" prop="role">
  154. <el-select v-model="insertForm.role" placeholder="请选择角色" style="width: 100%">
  155. <!-- <el-option label="普通员工" :value="0">
  156. <span style="float: left">普通员工</span>
  157. <span style="float: right; color: #8492a6; font-size: 13px">具有填报日报,参与项目协作基础功能</span>
  158. </el-option>
  159. <el-option label="系统管理员" :value="2" :disabled="user.role != 1">
  160. <span style="float: left">普通员工</span>
  161. <span style="float: right; color: #8492a6; font-size: 13px">具有填报日报,参与项目协作基础功能</span>
  162. </el-option>
  163. <el-option label="公司高层" :value="3"></el-option>
  164. <el-option label="人事管理员" :value="4"></el-option>
  165. <el-option label="项目管理员" :value="5"></el-option> -->
  166. <el-option v-for="item in roleDescArray" :label="item.label" :disabled="item.value==2&&user.role != 1" :value="item.value" :key="item.name">
  167. <span style="float: left">{{item.label}}</span>
  168. <span style="float: right; color: #8492a6; font-size: 13px">{{item.desc}}</span>
  169. </el-option>
  170. </el-select>
  171. </el-form-item>
  172. </el-form>
  173. <span slot="footer" class="dialog-footer">
  174. <el-button @click="dialogVisible=false">取消</el-button>
  175. <el-button type="primary" @click="submitInsert">提交</el-button>
  176. </span>
  177. </el-dialog>
  178. <el-dialog title="修改成本" :visible.sync="dialogVisible1" width="550px" >
  179. <el-form ref="form1" :model="insertForm" :rules="rules" label-width="80px">
  180. <el-form-item label="薪酬方式" prop="salaryType">
  181. <el-radio-group v-model="insertForm.salaryType" @change="onSalaryTypeChange">
  182. <el-radio :label="0" >固定月成本</el-radio>
  183. <el-radio :label="1">计时工资</el-radio>
  184. </el-radio-group>
  185. </el-form-item>
  186. <el-form-item label="月成本" prop="monthCost" v-if="insertForm.salaryType == 0">
  187. <el-input v-model="insertForm.monthCost" id="monthCost" @input="oninput" @keyup.native="restrictNumber('monthCost')" placeholder="请输入月成本,单位:元" clearable></el-input>
  188. <span style="color:orange;font-size:12px;">按照每个月工作{{timeType.monthDays}}天,每天{{timeType.allday}}小时预估时薪</span>
  189. <el-link :underline="false" style="color:blue;font-size:12px;margin-left:7px;" href="#/timetype">修改工作时长</el-link>
  190. </el-form-item>
  191. <el-form-item label="时薪" prop="cost">
  192. <el-input v-model="insertForm.cost" id="cost" :disabled="insertForm.salaryType == 0" @keyup.native="restrictNumber('cost')" style="width:120px;"
  193. placeholder="请输入成本 单位:元/小时" clearable></el-input>
  194. <span style="margin-left:25px;">生效日期</span>
  195. <el-date-picker v-model="insertForm.costApplyDate" value-format="yyyy-MM-dd"></el-date-picker>
  196. </el-form-item>
  197. <el-form-item label="部门" prop="departmentId">
  198. <el-cascader v-model="insertForm.departmentId"
  199. placeholder="请选择部门"
  200. style="width: 100%"
  201. :options="option"
  202. :props="{ checkStrictly: false,expandTrigger: 'hover' }" :show-all-levels="false"
  203. clearable></el-cascader>
  204. </el-form-item>
  205. </el-form>
  206. <span slot="footer" class="dialog-footer">
  207. <el-button @click="dialogVisible1=false">取消</el-button>
  208. <el-button type="primary" @click="submitInsert1">提交</el-button>
  209. </span>
  210. </el-dialog>
  211. <el-dialog title="人员历史成本" :visible.sync="userSalaryListDialog" width="550px" >
  212. <el-table :data="userSalaryList" highlight-current-row v-loading="listLoading" height="300px" style="width: 100%;">
  213. <el-table-column prop="userName" label="姓名" ></el-table-column>
  214. <el-table-column prop="indate" label="更新时间" width="150px">
  215. </el-table-column>
  216. <el-table-column prop="salaryType" label="薪酬方式" >
  217. <template slot-scope="scope" >
  218. {{scope.row.salaryType==0?"固定月薪":"计时工资"}}
  219. </template>
  220. </el-table-column>
  221. <el-table-column prop="monthCost" label="月薪" >
  222. <template slot-scope="scope" >
  223. {{scope.row.monthCost}}元
  224. </template>
  225. </el-table-column>
  226. <el-table-column prop="cost" label="时薪" >
  227. <template slot-scope="scope" >
  228. {{scope.row.cost}}元
  229. </template>
  230. </el-table-column>
  231. </el-table>
  232. </el-dialog>
  233. <!--导出人员 -->
  234. <el-dialog title="导出人员列表" :visible.sync="exportDialogVisible" width="550px" >
  235. <el-form label-width="100px">
  236. <el-form-item label="导出" >
  237. <el-radio-group v-model="containInvalid" >
  238. <el-radio :label="1" >全部人员</el-radio>
  239. <el-radio :label="0" >仅活跃人员</el-radio>
  240. </el-radio-group>
  241. </el-form-item>
  242. </el-form>
  243. <span slot="footer" class="dialog-footer">
  244. <el-button type="primary" @click="exportUsers">导出</el-button>
  245. </span>
  246. </el-dialog>
  247. <!-- 转让超级管理员权限 -->
  248. <el-dialog title="权限转让" :visible.sync="transferDialog" width="550px" >
  249. <el-form label-width="200px">
  250. <el-form-item label="转让超级管理员角色至" >
  251. <el-select v-model="toUserId" style="width:300px" filterable clearable>
  252. <el-option v-for="item in allActiveUsers" :key="item.id" :value="item.id" :label="item.name">
  253. </el-option>
  254. </el-select>
  255. </el-form-item>
  256. <el-form-item label="转让后自己的角色" >
  257. <el-select v-model="myRoleId" style="width:300px">
  258. <el-option v-for="item in roleDescArray" :label="item.label" :value="item.value" :key="item.name">
  259. <span style="float: left">{{item.label}}</span>
  260. <span style="float: right; color: #8492a6; font-size: 13px">{{item.desc}}</span>
  261. </el-option>
  262. </el-select>
  263. </el-form-item>
  264. </el-form>
  265. <span slot="footer" class="dialog-footer">
  266. <el-button type="default" @click="transferDialog = false">取消</el-button>
  267. <el-button type="primary" @click="showConfirmDialog">确定</el-button>
  268. </span>
  269. </el-dialog>
  270. <!--停用时选择日期 -->
  271. <el-dialog title="离职停用员工" :visible.sync="deactiveDialog" width="550px" >
  272. <el-form label-width="200px">
  273. <el-form-item label="员工离职日期" >
  274. <el-date-picker type="date" v-model="deactiveDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" placeholder="请选择" />
  275. </el-form-item>
  276. </el-form>
  277. <span slot="footer" class="dialog-footer">
  278. <el-button type="default" @click="deactiveDialog = false">取消</el-button>
  279. <el-button type="primary" @click="confirmDeactive">确定</el-button>
  280. </span>
  281. </el-dialog>
  282. </section>
  283. </template>
  284. <script>
  285. import util from "../../common/js/util";
  286. export default {
  287. data() {
  288. return {
  289. deactiveUser:null,
  290. deactiveDate:null,
  291. deactiveDialog:false,
  292. toUserId:null,
  293. myRoleId: 2,
  294. allActiveUsers:[],
  295. transferDialog: false,
  296. containInvalid:1,
  297. exportDialogVisible: false,
  298. roleArray:["普通员工","超级管理员", "系统管理员", "公司高层","人事管理员", "项目管理员","公司领导"],
  299. roleDescArray:[{label:"普通员工",value:0, desc:"填报日报,参与项目协作"},
  300. {label:"系统管理员",value:2, desc:"具有除了创建系统管理员之外的全部功能"},
  301. {label:"公司高层",value:3, desc:"查阅项目信息,人员工时情况"},
  302. {label:"人事管理员",value:4, desc:"财务核算成本,负责组织架构和薪资管理"},
  303. {label:"项目管理员",value:5, desc:"创建和管理项目"},
  304. {label:"公司领导",value:6, desc:"财务核算成本,查阅项目、人员工时和成本情况"},
  305. ],
  306. userSalaryList:[],
  307. userSalaryListDialog: false,
  308. value:{},
  309. user: JSON.parse(sessionStorage.getItem("user")),
  310. users:[],
  311. tableHeight: 0,
  312. listLoading: false,
  313. total: 0,
  314. page: 1,
  315. size: 20,
  316. list: [],
  317. data: [
  318. {
  319. id: -1,
  320. label: '全部人员',
  321. },
  322. {
  323. id: 0,
  324. label: '未分配',
  325. }
  326. ],
  327. option: [],
  328. depData: {
  329. id: -1,
  330. label: '全部人员',
  331. },
  332. defaultProps: {
  333. children: 'children',
  334. label: 'label'
  335. },
  336. dialogVisible: false,
  337. title: "",
  338. insertForm: {
  339. id: null,
  340. name: null,
  341. phone: null,
  342. role: null,
  343. monthCost:null,
  344. cost: null,
  345. departmentId: null,
  346. salaryType:0,
  347. costApplyDate: '2021-04-09'
  348. },
  349. rules: {
  350. name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
  351. // phone: [{ required: true, message: "请输入电话", trigger: "blur" }],
  352. role: [{ required: true, message: "请选择角色", trigger: "blur" }],
  353. cost: [{ required: true, message: "请输入成本", trigger: "blur" }]
  354. },
  355. dialogVisible1: false,
  356. departmentVisible: false,
  357. depTitle: '',
  358. depForm: {
  359. id: null,
  360. name: null,
  361. parentId: null,
  362. managerId: null,
  363. },
  364. depRules: {
  365. name: [{ required: true, message: "请输入部门名称", trigger: "blur" }],
  366. },
  367. timeType:{},
  368. };
  369. },
  370. methods: {
  371. confirmDeactive() {
  372. this.http.post('/user/deactiveUser', {
  373. id: this.deactiveUser.id,
  374. inactiveDate: this.deactiveDate
  375. },
  376. res => {
  377. if (res.code == "ok") {
  378. this.deactiveDialog = false;
  379. this.$message({
  380. message: '停用成功',
  381. type: "success"
  382. });
  383. // this.getUsers();
  384. this.getUser()
  385. } else {
  386. this.$message({
  387. message: res.msg,
  388. type: "error"
  389. });
  390. }
  391. },
  392. error => {
  393. this.$message({
  394. message: error,
  395. type: "error"
  396. });
  397. });
  398. },
  399. showDeactiveDialog(item) {
  400. this.deactiveDialog = true;
  401. this.deactiveUser = item;
  402. },
  403. restrictNumber(targetId) {
  404. let inpu = document.getElementById(targetId);
  405. inpu.value = inpu.value.replace(/[^\d.]/g, ""); //仅保留数字和"."
  406. inpu.value = inpu.value.replace(/\.{2,}/g, "."); //两个连续的"."仅保留第一个"."
  407. inpu.value = inpu.value.replace(".", "$#*").replace(/\./g,'').replace('$#*','.');//去除其他"."
  408. inpu.value = inpu.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2');;//限制只能输入两个小数
  409. if (inpu.value.indexOf(".") < 0 && inpu.value != "") { //首位是0的话去掉
  410. inpu.value = parseFloat(inpu.value);
  411. }
  412. },
  413. showConfirmDialog() {
  414. if (this.toUserId == null || this.toUserId == '') {
  415. this.$message({
  416. message: '请选择要转让的人员',
  417. type: "error"
  418. });
  419. return;
  420. }
  421. this.$confirm("您将失去超级管理员角色,需要重新登录。确定要转让吗?", "提示", {
  422. //type: 'warning'
  423. }).then(() => {
  424. this.http.post('/user/changeSysManager', {
  425. toUserId: this.toUserId,
  426. myRoleId: this.myRoleId
  427. },
  428. res => {
  429. if (res.code == "ok") {
  430. sessionStorage.removeItem("user");
  431. this.$router.push("/login");
  432. } else {
  433. this.$message({
  434. message: res.msg,
  435. type: "error"
  436. });
  437. }
  438. },
  439. error => {
  440. this.$message({
  441. message: error,
  442. type: "error"
  443. });
  444. });
  445. });
  446. },
  447. transferRole() {
  448. this.transferDialog = true;
  449. this.http.post(this.port.manage.list, {
  450. departmentId: -1,
  451. pageIndex: 1,
  452. pageSize: 99999
  453. },
  454. res => {
  455. if (res.code == "ok") {
  456. this.allActiveUsers = res.data.records.filter(u=>u.isActive == 1 && u.id != this.user.id);
  457. } else {
  458. this.$message({
  459. message: res.msg,
  460. type: "error"
  461. });
  462. }
  463. },
  464. error => {
  465. this.$message({
  466. message: error,
  467. type: "error"
  468. });
  469. });
  470. },
  471. showExportDialog() {
  472. this.exportDialogVisible = true;
  473. },
  474. exportUsers() {
  475. this.http.post('/user/exportUsers', {
  476. containInvalid: this.containInvalid
  477. },
  478. res => {
  479. if (res.code == "ok") {
  480. this.exportDialogVisible = false;
  481. var aTag = document.createElement('a');
  482. aTag.download = "全部员工列表.xls";
  483. aTag.href = res.data;
  484. aTag.click();
  485. } else {
  486. this.$message({
  487. message: res.msg,
  488. type: "error"
  489. });
  490. }
  491. },
  492. error => {
  493. this.$message({
  494. message: error,
  495. type: "error"
  496. });
  497. });
  498. },
  499. showSalaryList(item) {
  500. this.userSalaryListDialog = true;
  501. this.userSalaryList = [];
  502. this.http.post('/user/getUserSalaryList', {
  503. id: item.id
  504. },
  505. res => {
  506. if (res.code == "ok") {
  507. this.userSalaryList = res.data;
  508. } else {
  509. this.$message({
  510. message: res.msg,
  511. type: "error"
  512. });
  513. }
  514. },
  515. error => {
  516. this.$message({
  517. message: error,
  518. type: "error"
  519. });
  520. });
  521. },
  522. getUsers() {
  523. this.http.post(this.port.manage.list, {
  524. departmentId: -1,
  525. pageIndex: 1,
  526. pageSize: 99999
  527. },
  528. res => {
  529. if (res.code == "ok") {
  530. this.users = res.data.records;
  531. } else {
  532. this.$message({
  533. message: res.msg,
  534. type: "error"
  535. });
  536. }
  537. },
  538. error => {
  539. this.$message({
  540. message: error,
  541. type: "error"
  542. });
  543. });
  544. },
  545. onSalaryTypeChange(value) {
  546. if (value == 1) {
  547. this.insertForm.monthCost = null;
  548. }
  549. },
  550. //选中部门
  551. choseDept(value) {
  552. console.log(value);
  553. },
  554. //月成本输入变化
  555. oninput(e) {
  556. this.insertForm.cost = (this.insertForm.monthCost/this.timeType.monthDays/this.timeType.allday).toFixed(2);
  557. },
  558. // 获取本公司的工作时间设置
  559. getCompanyTimeSetting() {
  560. this.http.post('/time-type/getCompanyTimeSetting',{
  561. companyId: this.user.companyId
  562. },
  563. res => {
  564. if (res.code == "ok") {
  565. this.timeType = res.data;
  566. } else {
  567. this.$message({
  568. message: res.msg,
  569. type: "error"
  570. });
  571. }
  572. },
  573. error => {
  574. this.listLoading = false;
  575. this.$message({
  576. message: error,
  577. type: "error"
  578. });
  579. }
  580. );
  581. },
  582. // 批量导入人员
  583. importUser(item) {
  584. //首先判断文件类型
  585. let str = item.file.name.split(".");
  586. let format = str[str.length - 1];
  587. if (format != "xls" && format != "xlsx") {
  588. this.$message({
  589. message: "请选择.xls或.xlsx文件",
  590. type: "error"
  591. });
  592. } else {
  593. this.listLoading = true;
  594. let formData = new FormData();
  595. formData.append("file", item.file);
  596. formData.append("departmentId", this.depData.id);
  597. this.http.uploadFile( this.port.manage.import, formData,
  598. res => {
  599. this.$refs.upload.clearFiles();
  600. this.listLoading = false;
  601. if (res.code == "ok") {
  602. this.$message({
  603. message: "导入成功",
  604. type: "success"
  605. });
  606. //重新读取列表
  607. this.getUser();
  608. } else {
  609. this.$message({
  610. message: res.msg,
  611. type: "error"
  612. });
  613. }
  614. },
  615. error => {
  616. this.$refs.upload.clearFiles();
  617. this.listLoading = false;
  618. this.$message({
  619. message: error,
  620. type: "error"
  621. });
  622. });
  623. }
  624. },
  625. //分页
  626. handleCurrentChange(val) {
  627. this.page = val;
  628. this.getUser();
  629. },
  630. handleSizeChange(val) {
  631. this.size = val;
  632. this.getUser();
  633. },
  634. //获取所有员工的列表
  635. getUser() {
  636. this.listLoading = true;
  637. this.http.post( this.port.manage.list, {
  638. departmentId: this.depData.id,
  639. pageIndex: this.page,
  640. pageSize: this.size
  641. },
  642. res => {
  643. this.listLoading = false;
  644. if (res.code == "ok") {
  645. this.list = res.data.records;
  646. this.total = res.data.total;
  647. } else {
  648. this.$message({
  649. message: res.msg,
  650. type: "error"
  651. });
  652. }
  653. },
  654. error => {
  655. this.listLoading = false;
  656. this.$message({
  657. message: error,
  658. type: "error"
  659. });
  660. });
  661. },
  662. resetPwd(user) {
  663. this.$confirm( "确定要为" + user.name + "重置密码吗?", "重置密码", {
  664. confirmButtonText: "确定",
  665. cancelButtonText: "取消",
  666. type: "warning"
  667. })
  668. .then(() => {
  669. this.http.post('/user/resetPwd', { userId: user.id },
  670. res => {
  671. if (res.code == "ok") {
  672. this.$message({
  673. message: "密码已重置为000000,请通知员工及时修改",
  674. type: "success"
  675. });
  676. } else {
  677. this.$message({
  678. message: res.msg,
  679. type: "error"
  680. });
  681. }
  682. },
  683. error => {
  684. this.listLoading = false;
  685. this.$message({
  686. message: error,
  687. type: "error"
  688. });
  689. });
  690. })
  691. .catch(() => {});
  692. },
  693. // 新增、编辑人员
  694. openInsertDialog(i) {
  695. if (i != null) {
  696. var list = JSON.parse(JSON.stringify(this.list[i])) , arr = [] , array = [];
  697. if(list.departmentCascade!='0' && list.departmentCascade!=null) {
  698. if(list.departmentCascade.indexOf(",")>-1) {
  699. arr = list.departmentCascade.split(",");
  700. } else {
  701. arr = [].concat(list.departmentCascade)
  702. }
  703. }
  704. for(var i in arr) {
  705. array.push(parseInt(arr[i]))
  706. }
  707. this.insertForm = {
  708. id: list.id,
  709. name: list.name,
  710. phone: list.phone,
  711. role: list.role,
  712. monthCost:list.monthCost,
  713. cost: list.cost,
  714. departmentId: array.reverse(),
  715. salaryType: list.salaryType,
  716. costApplyDate: list.costApplyDate,
  717. };
  718. this.title = "编辑人员"
  719. } else {
  720. this.insertForm = {
  721. id: null,
  722. name: null,
  723. phone: null,
  724. role: null,
  725. monthCost:null,
  726. cost: null,
  727. departmentId: null,
  728. salaryType:0,
  729. costApplyDate: util.formatDate.format(new Date(), 'yyyy-MM-dd'),
  730. };
  731. this.title = "新增人员"
  732. }
  733. this.dialogVisible = true;
  734. },
  735. submitInsert() {
  736. this.$refs.form1.validate(valid => {
  737. if (valid) {
  738. this.listLoading = true;
  739. var form = {
  740. name: this.insertForm.name,
  741. phone: this.insertForm.phone,
  742. role: this.insertForm.role,
  743. monthCost: this.insertForm.monthCost,
  744. cost: this.insertForm.cost,
  745. salaryType: this.insertForm.salaryType,
  746. };
  747. if (this.insertForm.id != null) {
  748. form.id = this.insertForm.id;
  749. }
  750. if (this.insertForm.costApplyDate != null) {
  751. form.costApplyDate = this.insertForm.costApplyDate;
  752. }
  753. if (this.insertForm.departmentId != null) {
  754. form.departmentId = this.insertForm.departmentId[this.insertForm.departmentId.length-1];
  755. }
  756. this.http.post( this.port.manage.insert, form,
  757. res => {
  758. this.listLoading = false;
  759. if (res.code == "ok") {
  760. this.$message({
  761. message: this.insertForm.id != null ? "修改" : "创建" + "成功",
  762. type: "success"
  763. });
  764. this.dialogVisible = false;
  765. this.getUser();
  766. } else {
  767. this.$message({
  768. message: res.msg,
  769. type: "error"
  770. });
  771. }
  772. },
  773. error => {
  774. this.listLoading = false;
  775. this.$message({
  776. message: error,
  777. type: "error"
  778. });
  779. });
  780. }
  781. });
  782. },
  783. // 切换角色
  784. switchRole(index) {
  785. this.listLoading = true;
  786. this.http.post( this.port.manage.permission, { id: this.list[index].id },
  787. res => {
  788. this.listLoading = false;
  789. if (res.code == "ok") {
  790. this.$message({
  791. message: "切换角色成功",
  792. type: "success"
  793. });
  794. //重新读取列表
  795. this.getUser();
  796. } else {
  797. this.$message({
  798. message: res.msg,
  799. type: "error"
  800. });
  801. }
  802. },
  803. error => {
  804. this.listLoading = false;
  805. this.$message({
  806. message: error,
  807. type: "error"
  808. });
  809. });
  810. },
  811. // 删除用户
  812. setActive(item, isActive) {
  813. var txt = isActive==1?"启用":"停用";
  814. this.$confirm( "确定要"+txt +" " + item.name + " 吗?", "账号"+txt, {
  815. confirmButtonText: "确定",
  816. cancelButtonText: "取消",
  817. type: "warning"
  818. })
  819. .then(() => {
  820. this.listLoading = true;
  821. this.http.post('/user/setActive', { id: item.id, isActive: isActive},
  822. res => {
  823. this.listLoading = false;
  824. if (res.code == "ok") {
  825. this.$message({
  826. message: txt+"成功",
  827. type: "success"
  828. });
  829. //重新读取列表
  830. this.getUser();
  831. } else {
  832. this.$message({
  833. message: res.msg,
  834. type: "error"
  835. });
  836. }
  837. },
  838. error => {
  839. this.listLoading = false;
  840. this.$message({
  841. message: error,
  842. type: "error"
  843. });
  844. });
  845. })
  846. .catch(() => {});
  847. },
  848. // 修改老板的成本
  849. openInsertDialog1(i) {
  850. var list1 = JSON.parse(JSON.stringify(this.list[i])) , arr1 = [] , array1 = [];
  851. if(list1.departmentCascade!='0' && list1.departmentCascade!=null) {
  852. if(list1.departmentCascade.indexOf(",")>-1) {
  853. arr1 = list1.departmentCascade.split(",");
  854. } else {
  855. arr1 = [].concat(list1.departmentCascade)
  856. }
  857. }
  858. for(var i in arr1) {
  859. array1.push(parseInt(arr1[i]))
  860. }
  861. this.insertForm = {
  862. id: list1.id,
  863. name: list1.name,
  864. phone: list1.phone,
  865. role: list1.role,
  866. monthCost:list1.monthCost,
  867. cost: list1.cost,
  868. departmentId: array1.reverse(),
  869. salaryType: list1.salaryType
  870. };
  871. this.dialogVisible1 = true;
  872. },
  873. submitInsert1() {
  874. this.$refs.form1.validate(valid => {
  875. if (valid) {
  876. this.listLoading = true;
  877. var form = {
  878. id: this.insertForm.id,
  879. name: this.insertForm.name,
  880. phone: this.insertForm.phone,
  881. role: this.insertForm.role,
  882. monthCost: this.insertForm.monthCost,
  883. cost: this.insertForm.cost
  884. };
  885. if (this.insertForm.departmentId != null) {
  886. form.departmentId = this.insertForm.departmentId[this.insertForm.departmentId.length-1];
  887. }
  888. if (this.insertForm.costApplyDate != null) {
  889. form.costApplyDate = this.insertForm.costApplyDate;
  890. }
  891. this.http.post( this.port.manage.insert, form,
  892. res => {
  893. this.listLoading = false;
  894. if (res.code == "ok") {
  895. this.$message({
  896. message: "修改成功",
  897. type: "success"
  898. });
  899. this.dialogVisible1 = false;
  900. //重新读取列表
  901. this.getUser();
  902. } else {
  903. this.$message({
  904. message: res.msg,
  905. type: "error"
  906. });
  907. }
  908. },
  909. error => {
  910. this.listLoading = false;
  911. this.$message({
  912. message: error,
  913. type: "error"
  914. });
  915. });
  916. }
  917. });
  918. },
  919. // 获取部门列表
  920. getDepartment() {
  921. this.http.post( this.port.manage.depList, {},
  922. res => {
  923. if (res.code == "ok") {
  924. var list = res.data , list1 = JSON.parse(JSON.stringify(res.data));
  925. list.splice(0,0,{
  926. id: -1,
  927. label: '全部人员',
  928. })
  929. list.push({
  930. id: 0,
  931. label: '未分配',
  932. })
  933. this.data = list;
  934. this.option = this.changeArr(list1);
  935. } else {
  936. this.$message({
  937. message: res.msg,
  938. type: "error"
  939. });
  940. }
  941. },
  942. error => {
  943. this.$message({
  944. message: error,
  945. type: "error"
  946. });
  947. });
  948. },
  949. // 修改数组
  950. changeArr(arr) {
  951. for (var i = 0; i < arr.length; i++) {
  952. if(arr[i].id != -1 && arr[i].id != 0) {
  953. if (arr[i].children != null && arr[i].children.length>0) {
  954. arr[i].children = this.changeArr(arr[i].children);
  955. }
  956. arr[i].id && (arr[i].value = arr[i].id);
  957. delete arr[i].id;
  958. }
  959. }
  960. for(var i in arr) {
  961. if(arr[i].id == -1 || arr[i].id == 0) {
  962. arr.splice(i,1)
  963. }
  964. }
  965. return arr;
  966. },
  967. // 部门列表点击
  968. handleNodeClick(data) {
  969. if(this.depData == null || data.id != this.depData.id) {
  970. this.depData = data;
  971. this.page = 1;
  972. this.getUser();
  973. }
  974. },
  975. // 新增、修改部门
  976. createDepartment(i) {
  977. if(i == -2) {//创建子部门
  978. this.depForm = {
  979. id: null,
  980. name: null,
  981. parentId: null,
  982. managerId: null,
  983. }
  984. if(this.depData.id != -1 && this.depData.id != 0) {
  985. this.depForm.parentId = this.depData.id;
  986. }
  987. this.depTitle = "新增子部门";
  988. } else if(i == -1) {//创建一级部门
  989. this.depForm = {
  990. id: null,
  991. name: null,
  992. parentId: null,
  993. managerId: null,
  994. }
  995. this.depTitle = "新增部门";
  996. } else {
  997. this.depForm = {
  998. id: this.depData.id,
  999. name: this.depData.label,
  1000. parentId: this.depData.parentId,
  1001. managerId: this.depData.managerId,
  1002. }
  1003. this.depTitle = "编辑部门";
  1004. }
  1005. this.departmentVisible = true;
  1006. },
  1007. submitDepartment() {
  1008. this.$refs.depForm.validate(valid => {
  1009. if (valid) {
  1010. var form = {
  1011. name: this.depForm.name,
  1012. };
  1013. if(this.depForm.id != null) {
  1014. form.id = this.depForm.id
  1015. }
  1016. if(this.depForm.parentId != null) {
  1017. form.parentId = this.depForm.parentId
  1018. }
  1019. if (this.depForm.managerId != null) {
  1020. form.managerId = this.depForm.managerId
  1021. }
  1022. this.http.post( this.depForm.id==null?this.port.manage.add:this.port.manage.edit, form,
  1023. res => {
  1024. if (res.code == "ok") {
  1025. this.$message({
  1026. message: this.depForm.id==null?"新增成功":"修改成功",
  1027. type: "success"
  1028. });
  1029. this.departmentVisible = false;
  1030. if (this.depForm.id !=null) {
  1031. this.depData.label = form.name;
  1032. this.depData.managerId = form.managerId;
  1033. }
  1034. this.getDepartment();
  1035. } else {
  1036. this.$message({
  1037. message: res.msg,
  1038. type: "error"
  1039. });
  1040. }
  1041. },
  1042. error => {
  1043. this.listLoading = false;
  1044. this.$message({
  1045. message: error,
  1046. type: "error"
  1047. });
  1048. });
  1049. }
  1050. });
  1051. },
  1052. // 删除部门
  1053. deleteDep() {
  1054. this.$confirm( "确定要删除部门" + this.depData.label + "吗?", "删除部门", {
  1055. confirmButtonText: "确定",
  1056. cancelButtonText: "取消",
  1057. type: "warning"
  1058. })
  1059. .then(() => {
  1060. this.listLoading = true;
  1061. this.http.post( this.port.manage.del, { id: this.depData.id },
  1062. res => {
  1063. this.listLoading = false;
  1064. if (res.code == "ok") {
  1065. this.$message({
  1066. message: "删除成功",
  1067. type: "success"
  1068. });
  1069. this.depData = {
  1070. id: -1,
  1071. label: '全部人员',
  1072. }
  1073. this.getDepartment();
  1074. this.getUser();
  1075. } else {
  1076. this.$message({
  1077. message: res.msg,
  1078. type: "error"
  1079. });
  1080. }
  1081. },
  1082. error => {
  1083. this.listLoading = false;
  1084. this.$message({
  1085. message: error,
  1086. type: "error"
  1087. });
  1088. });
  1089. })
  1090. .catch(() => {});
  1091. },
  1092. },
  1093. created() {
  1094. let height = window.innerHeight;
  1095. this.tableHeight = height - 195;
  1096. const that = this;
  1097. window.onresize = function temp() {
  1098. that.tableHeight = window.innerHeight - 195;
  1099. };
  1100. },
  1101. mounted() {
  1102. this.deactiveDate = util.formatDate.format(new Date(), 'yyyy-MM-dd');
  1103. this.getDepartment();
  1104. this.getUser();
  1105. this.getCompanyTimeSetting();
  1106. this.getUsers();
  1107. }
  1108. };
  1109. </script>
  1110. <style lang="scss" scoped>
  1111. .left {
  1112. border-right: 1px solid #f2f2f2;
  1113. overflow: hidden;
  1114. .department {
  1115. background:#f2f2f2;
  1116. line-height: 60px;
  1117. color:#666;
  1118. padding:0 10px;
  1119. height:60px;
  1120. font-size: 15px;
  1121. div {
  1122. float: right;
  1123. color: #20a0ff;
  1124. font-size: 14px;
  1125. cursor: pointer;
  1126. }
  1127. }
  1128. .tree {
  1129. overflow: auto;
  1130. }
  1131. }
  1132. .nowTime {
  1133. height: 40px;
  1134. line-height: 40px;
  1135. font-size: 16px;
  1136. color: #20a0ff;
  1137. margin-left: 10px;
  1138. cursor: pointer;
  1139. i {
  1140. margin-right: 10px;
  1141. }
  1142. }
  1143. </style>
  1144. <style lang="scss">
  1145. .tree {
  1146. .el-tree-node__label {
  1147. overflow-x: hidden;
  1148. white-space: nowrap;
  1149. text-overflow: ellipsis;
  1150. }
  1151. }
  1152. .el-divider--horizontal {
  1153. margin: 0px;
  1154. background:#f3f3f3;
  1155. }
  1156. //全局的作用范围
  1157. .el-tree-node__content {
  1158. height:36px;
  1159. }
  1160. </style>