index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <!--组织架构-->
  2. <template>
  3. <div class="app-container dept">
  4. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
  5. <el-form-item label="部门名称" prop="deptName">
  6. <el-input
  7. v-model="queryParams.deptName"
  8. placeholder="请输入部门名称"
  9. clearable
  10. size="small"
  11. />
  12. </el-form-item>
  13. <el-form-item>
  14. <p class="inquire-button-one" @click="handleQuery">查询</p>
  15. <p class="reset-button-one" @click="resetQuery">重置</p>
  16. </el-form-item>
  17. </el-form>
  18. <el-table border
  19. v-loading="loading"
  20. :data="deptList"
  21. row-key="deptId"
  22. default-expand-all
  23. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  24. >
  25. <el-table-column prop="deptName" label="部门名称">
  26. <template slot-scope="scope">
  27. <img v-if="scope.row.deptImg" class="scope-img" :src="scope.row.deptImg">
  28. <p class="scope-name">{{ scope.row.deptName }}</p>
  29. </template>
  30. </el-table-column>
  31. <el-table-column prop="deptSign" label="电子签章" >
  32. <template slot-scope="scope">
  33. <img :src="scope.row.deptSign" style="width:40px;height:40px;" @click="lookSign(2,scope.row.deptSign)">
  34. </template>
  35. </el-table-column>
  36. <el-table-column prop="isLower" label="适用下级" >
  37. <template slot-scope="scope">
  38. {{scope.row.isLower == 0?'否':'是'}}
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="操作" width="120" v-if="tableButtonType">
  42. <template slot-scope="scope">
  43. <div class="table-button-box">
  44. <p class="table-button-null"></p>
  45. <p class="table-button-p"
  46. v-hasPermi="['system:dept_sign:edit']"
  47. @click="addButton(scope.row)"
  48. >编辑</p>
  49. <p class="table-button-null"></p>
  50. </div>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. <el-dialog class="up-img-box" title="电子签章" :visible.sync="upFaceOpen" width="600px" append-to-body :close-on-click-modal="false">
  55. <el-form ref="form" :model="upFaceForm" :rules="rules">
  56. <el-form-item label="是否适用下级" prop="isLower" style="margin-top:30px;" label-width="140px">
  57. <el-select v-model="upFaceForm.isLower" placeholder="请选择是否适用下级" style="width:300px;">
  58. <el-option label="是" :value="1" />
  59. <el-option label="否" :value="0" />
  60. </el-select>
  61. </el-form-item>
  62. <el-form-item label="" prop="deptSign" style="width:200px;cursor: pointer;margin:20px 180px 0;">
  63. <el-upload
  64. @click="upImgOpenClick(1)"
  65. style="width:200px;height:200px;cursor: pointer;overflow: hidden"
  66. class="position-button"
  67. :action="uploadImgUrl"
  68. :show-file-list="false"
  69. accept="image/jpeg,image/gif,image/png"
  70. :on-success="handleAvatarSuccess"
  71. :headers="headers"
  72. :before-upload="beforeAvatarUpload">
  73. <div v-if="!upFaceForm.deptSign" style="width:200px;height:200px;border: 1px dashed #E0E0E0;">
  74. <p style="text-align: center;color:#999;font-weight:500;font-size: 20px;line-height:200px;margin:0;">+</p>
  75. </div>
  76. <img :src="upFaceForm.deptSign" v-if="upFaceForm.deptSign" style="width:198px;height:198px;cursor: pointer;">
  77. </el-upload>
  78. </el-form-item>
  79. </el-form>
  80. <div slot="footer" class="dialog-footer">
  81. <el-button @click="deptSignUp(1)">取 消</el-button>
  82. <el-button type="primary" @click="deptSignUp(2)">确 定</el-button>
  83. </div>
  84. </el-dialog>
  85. <!-- 添加或修改部门对话框 -->
  86. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :close-on-click-modal="false">
  87. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  88. <el-row>
  89. <el-col :span="12">
  90. <el-form-item label="部门名称" prop="deptName">
  91. <el-input v-model="form.deptName" placeholder="请输入部门名称" />
  92. </el-form-item>
  93. </el-col>
  94. <el-col :span="12">
  95. <el-form-item label="显示排序" prop="orderNum">
  96. <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
  97. </el-form-item>
  98. </el-col>
  99. </el-row>
  100. </el-form>
  101. <div slot="footer" class="dialog-footer">
  102. <el-button @click="cancel">取 消</el-button>
  103. <el-button type="primary" @click="submitForm">确 定</el-button>
  104. </div>
  105. </el-dialog>
  106. <el-dialog title="电子签章" :visible.sync="signType" width="600px" append-to-body :close-on-click-modal="false">
  107. <img :src="signUrl" style="width:300px;height:300px;display: block;margin:0 auto;">
  108. <div slot="footer" class="dialog-footer">
  109. <el-button type="primary" @click="lookSign(1)" style="width:100px; margin:0 auto;display: block;">确 定</el-button>
  110. </div>
  111. </el-dialog>
  112. </div>
  113. </template>
  114. <script>
  115. import { listDept,listDeptVO, getDept, delDept, addDept, updateDept, listDeptExcludeChild,signList,deptSign } from "@/api/system/dept";
  116. import Treeselect from "@riophae/vue-treeselect";
  117. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  118. import { getToken } from "@/utils/auth";
  119. export default {
  120. name: "Dept",
  121. components: { Treeselect },
  122. data() {
  123. return {
  124. tableButtonType:this.hasPermiDom(['system:dept_sign:edit']),
  125. uploadImgUrl: this.uploadUrl(), // 上传的图片服务器地址
  126. headers: {
  127. Authorization: "Bearer " + getToken(),
  128. },
  129. // 遮罩层
  130. loading: true,
  131. // 显示搜索条件
  132. showSearch: true,
  133. // 表格树数据
  134. deptList: [],
  135. // 部门树选项
  136. deptOptions: [],
  137. // 弹出层标题
  138. title: "",
  139. // 是否显示弹出层
  140. open: false,
  141. // 状态数据字典
  142. statusOptions: [],
  143. // 查询参数
  144. queryParams: {
  145. deptName: undefined,
  146. status: undefined
  147. },
  148. // 表单参数
  149. form: {},
  150. // 表单校验
  151. rules: {
  152. isLower: [
  153. { required: true, message: "请选择是否适用下级", trigger: "blur" }
  154. ],
  155. deptSign: [
  156. { required: true, message: "请上传签章", trigger: "blur" }
  157. ],
  158. parentId: [
  159. { required: true, message: "上级部门不能为空", trigger: "blur" }
  160. ],
  161. deptName: [
  162. { required: true, message: "部门名称不能为空", trigger: "blur" },
  163. { required: true, message: "部门名称不能为空", validator: this.spaceJudgment, trigger: "blur" }
  164. ],
  165. orderNum: [
  166. { required: true, message: "显示排序不能为空", trigger: "blur" },
  167. { required: true, message: "显示排序不能为空", validator: this.spaceJudgment, trigger: "blur" }
  168. ],
  169. email: [
  170. {
  171. type: "email",
  172. message: "'请输入正确的邮箱地址",
  173. trigger: ["blur", "change"]
  174. },
  175. { required: true, message: "请输入正确的邮箱地址", validator: this.spaceJudgment, trigger: "blur" }
  176. ],
  177. phone: [
  178. {
  179. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  180. message: "请输入正确的联系方式",
  181. trigger: "blur"
  182. },
  183. { required: true, message: "请输入正确的联系方式", validator: this.spaceJudgment, trigger: "blur" }
  184. ],
  185. type:[
  186. { required: true, message: "请选择是否适用下级", trigger: "blur" }
  187. ]
  188. },
  189. //电子签章
  190. upFaceOpen:false,
  191. upFaceForm:{
  192. type:"",
  193. },
  194. upFaceUrl:"",
  195. signType:false,
  196. signUrl:"",
  197. };
  198. },
  199. created() {
  200. this.getList();
  201. this.getDicts("sys_normal_disable").then(response => {
  202. this.statusOptions = response.data;
  203. });
  204. },
  205. methods: {
  206. //签章编辑窗口按钮
  207. deptSignUp(type){
  208. if(type == 1){
  209. this.upFaceOpen = false;
  210. }else if(type == 2){
  211. this.$refs["form"].validate(valid => {
  212. if (valid) {
  213. let obj = {
  214. deptId:this.upFaceForm.deptId,
  215. isLower:this.upFaceForm.isLower,
  216. deptSign:this.upFaceForm.deptSign,
  217. }
  218. deptSign(obj).then(response => {
  219. this.msgSuccess(response.msg);
  220. this.upFaceOpen = false;
  221. this.getList();
  222. })
  223. }
  224. })
  225. }
  226. },
  227. //查看签章
  228. lookSign(type,url){
  229. if(type == 1){
  230. this.signType = false;
  231. }else if(type == 2){
  232. this.signUrl = url;
  233. this.signType = true;
  234. }
  235. },
  236. //编辑签章
  237. addButton(row){
  238. this.upFaceForm = JSON.parse(JSON.stringify(row));
  239. if(!this.upFaceForm.isLower){
  240. this.upFaceForm.isLower = 0;
  241. }
  242. this.upFaceUrl = this.upFaceForm.deptSign;
  243. this.upFaceOpen = true;
  244. },
  245. //上传
  246. handleAvatarSuccess(res) {
  247. console.log(res.data.url);
  248. this.upFaceForm.deptSign = res.data.url;
  249. this.$forceUpdate()
  250. },
  251. beforeAvatarUpload(file) {
  252. let type = false;
  253. console.log('file',file);
  254. if (file.type == 'image/png' || file.type == 'image/jpeg' || file.type == 'image/gif') {
  255. type = true;
  256. }else{
  257. this.$message.error('只能上传png/jpeg/gif格式图片');
  258. type = false;
  259. }
  260. return type;
  261. },
  262. /** 查询部门列表 */
  263. getList() {
  264. let self = this;
  265. this.loading = true;
  266. signList(this.queryParams).then(response => {
  267. this.deptList = this.handleTree(response.data, "deptId");
  268. let num = this.getDepth(this.deptList,1)+10;
  269. let listA = JSON.parse(JSON.stringify(response.data));
  270. let listB = [];
  271. //deptId 本身的名字 parentId 父名
  272. for(let i=0;i<num;i++){
  273. console.log("num===",i)
  274. for(let o=0;o<listA.length;o++){
  275. let age = 0;
  276. for(let k=0;k<listA.length;k++){
  277. if(listA[o].deptId == listA[k].parentId){
  278. age++
  279. console.log(listA[o].deptId,listA[o].deptName)
  280. console.log(listA[k].parentId,listA[k].deptName)
  281. break
  282. }
  283. }
  284. if(age==0){
  285. for(let k=0;k<listA.length;k++){
  286. if(listA[o].parentId == listA[k].deptId){
  287. listA[k].totalPeople = listA[k].totalPeople + listA[o].totalPeople;
  288. listA[k].totalSub = listA[k].totalSub + listA[o].totalSub;
  289. listB.push(listA[o]);
  290. listA.splice(o,1);
  291. console.log("listA",listA)
  292. console.log("listB",listB)
  293. break
  294. // return
  295. }
  296. }
  297. }
  298. }
  299. if(listA.length == 1){
  300. listB.push(listA[0]);
  301. break
  302. }
  303. }
  304. this.deptList = this.handleTree(listB, "deptId");
  305. this.loading = false;
  306. });
  307. },
  308. /** 转换部门数据结构 */
  309. normalizer(node) {
  310. if (node.children && !node.children.length) {
  311. delete node.children;
  312. }
  313. return {
  314. id: node.deptId,
  315. label: node.deptName,
  316. children: node.children
  317. };
  318. },
  319. // 字典状态字典翻译
  320. statusFormat(row, column) {
  321. return this.selectDictLabel(this.statusOptions, row.status);
  322. },
  323. // 取消按钮
  324. cancel() {
  325. this.open = false;
  326. this.reset();
  327. },
  328. // 表单重置
  329. reset() {
  330. this.form = {
  331. deptId: undefined,
  332. parentId: undefined,
  333. deptName: undefined,
  334. orderNum: undefined,
  335. leader: undefined,
  336. phone: undefined,
  337. email: undefined,
  338. status: "0"
  339. };
  340. this.resetForm("form");
  341. },
  342. /** 搜索按钮操作 */
  343. handleQuery() {
  344. this.getList();
  345. },
  346. /** 重置按钮操作 */
  347. resetQuery() {
  348. this.resetForm("queryForm");
  349. this.handleQuery();
  350. },
  351. /** 新增按钮操作 */
  352. handleAdd(row) {
  353. this.reset();
  354. if (row != undefined) {
  355. this.form.parentId = row.deptId;
  356. }
  357. this.open = true;
  358. this.title = "添加部门";
  359. listDept().then(response => {
  360. this.deptOptions = this.handleTree(response.data, "deptId");
  361. });
  362. },
  363. /** 修改按钮操作 */
  364. handleUpdate(row) {
  365. this.reset();
  366. getDept(row.deptId).then(response => {
  367. this.form = response.data;
  368. this.open = true;
  369. this.title = "修改部门";
  370. });
  371. listDeptExcludeChild(row.deptId).then(response => {
  372. this.deptOptions = this.handleTree(response.data, "deptId");
  373. });
  374. },
  375. /** 提交按钮 */
  376. submitForm: function() {
  377. this.$refs["form"].validate(valid => {
  378. if (valid) {
  379. if (this.form.deptId != undefined) {
  380. updateDept(this.form).then(response => {
  381. this.msgSuccess("修改成功");
  382. this.open = false;
  383. this.getList();
  384. });
  385. } else {
  386. addDept(this.form).then(response => {
  387. this.msgSuccess("新增成功");
  388. this.open = false;
  389. this.getList();
  390. });
  391. }
  392. }
  393. });
  394. },
  395. /** 删除按钮操作 */
  396. handleDelete(row) {
  397. this.$confirm('是否确认删除?', "警告", {
  398. confirmButtonText: "确定",
  399. cancelButtonText: "取消",
  400. type: "warning"
  401. }).then(function() {
  402. return delDept(row.deptId);
  403. }).then(() => {
  404. this.getList();
  405. this.msgSuccess("删除成功");
  406. }).catch(() => {});
  407. },
  408. //计算层级
  409. getDepth(arr, depth) {
  410. var flag = false;
  411. var temp = [];
  412. for (let i = 0; i < arr.length; i++) {
  413. if (arr[i].children instanceof Array) { // 判断是否是数组
  414. for (let j = 0; j < arr[i].children.length; j++) {
  415. temp.push(arr[i].children[j]); // 解析出arr下第一层
  416. }
  417. flag = true;
  418. }
  419. }
  420. if (flag) { // 如果还有数组,则继续解析,直到最后一层有不为数组为止
  421. depth++;
  422. return this.getDepth(temp, depth);
  423. } else {
  424. return depth;
  425. }
  426. },
  427. //加法
  428. accAdd(arg1,arg2){
  429. var r1,r2,m;
  430. try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
  431. try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
  432. m=Math.pow(10,Math.max(r1,r2))
  433. return ((arg1*m+arg2*m)/m).toFixed(0);
  434. },
  435. }
  436. };
  437. </script>
  438. <style scoped lang="scss">
  439. .dept {
  440. display: flex!important;
  441. flex-direction: column;
  442. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  443. padding:11px 20px 20px!important;
  444. .button-box{
  445. width:300px;
  446. display: flex;
  447. }
  448. }
  449. </style>