index.vue 43 KB

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