Department.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <template>
  2. <div>
  3. <div class="communal-list">
  4. <div class="communal-title">
  5. <div>部门列表</div>
  6. <div class="communal-box">
  7. <el-input @input="Inquireclick()" placeholder="请输入内容" v-model="input" clearable>
  8. </el-input>
  9. <el-button @click="Inquireclick()" type="primary"><i class="icon-sousuo"></i></el-button>
  10. <el-button @click="addDepartment()" type="primary">新增</el-button>
  11. </div>
  12. </div>
  13. <template>
  14. <el-table :data="tableDatas.slice((currentPage - 1) * pageSize, currentPage * pageSize)" border
  15. style="width: 100%">
  16. <el-table-column prop="num" label="序 号" width="55">
  17. <template slot-scope="scope">
  18. {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
  19. </template>
  20. </el-table-column>
  21. <el-table-column prop="depCode" label="部门Code" width="100">
  22. </el-table-column>
  23. <el-table-column prop="depName" label="部门名称" width="200">
  24. </el-table-column>
  25. <el-table-column prop="companyName" label="所属公司" width="220">
  26. </el-table-column>
  27. <el-table-column prop="parentDepName" label="上级部门" width="100">
  28. </el-table-column>
  29. <el-table-column prop="remark" label="备注" width="240">
  30. </el-table-column>
  31. <el-table-column label="操作" width="200">
  32. <template slot-scope="scope">
  33. <el-button size="mini" @click="upDate(scope.$index, scope.row)">编辑</el-button>
  34. <el-button size="mini" type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
  35. </template>
  36. </el-table-column>
  37. </el-table>
  38. </template>
  39. <div class="block">
  40. <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange"
  41. :current-page="currentPage" :page-sizes="[10, 15, 20]" :page-size="pageSize"
  42. layout="total, sizes, prev, pager, next" :total="tableDatas.length">
  43. </el-pagination>
  44. </div>
  45. </div>
  46. <el-dialog title="添加部门" :visible.sync="addDepVisible" width="30%" :before-close="handleClose">
  47. <div>
  48. <el-form :model="addData" :rules="rules" ref="addData" label-width="100px" class="demo-ruleForm">
  49. <el-form-item label="部门code" prop="DepCode">
  50. <el-input placeholder="请输入内容" v-model="addData.DepCode">
  51. </el-input>
  52. </el-form-item>
  53. <el-form-item label="部门名称" prop="DepName">
  54. <el-input placeholder="请输入内容" v-model="addData.DepName">
  55. </el-input>
  56. </el-form-item>
  57. <el-form-item label="所属公司" prop="CompanyId">
  58. <el-select v-model="addData.CompanyId" filterable placeholder="请选择所属公司" @change="handleChange">
  59. <el-option v-for="item in optionsCompanys" :key="item.value" :label="item.label"
  60. :value="item.value">
  61. </el-option>
  62. </el-select>
  63. </el-form-item>
  64. <el-form-item label="上级部门" prop="ParentDepId">
  65. <el-select v-model="addData.ParentDepId" placeholder="请选择上级部门">
  66. <el-option v-for="item in optionsDepartment" :key="item.value" :label="item.label"
  67. :value="item.value">
  68. </el-option>
  69. </el-select>
  70. </el-form-item>
  71. <el-form-item label="备 注" prop="Remark">
  72. <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="addData.Remark"></el-input>
  73. </el-form-item>
  74. </el-form>
  75. </div>
  76. <span slot="footer" class="dialog-footer">
  77. <el-button @click="addDepVisible = false">取 消</el-button>
  78. <el-button type="primary" @click="Addbtn">确 定</el-button>
  79. </span>
  80. </el-dialog>
  81. <el-dialog title="修改部门" :visible.sync="upDepVisible" width="30%" :before-close="handleClose">
  82. <div>
  83. <el-form :model="upData" :rules="rules" ref="upData" label-width="100px" class="demo-ruleForm">
  84. <el-form-item label="部门code" prop="DepCode">
  85. <el-input placeholder="请输入内容" v-model="upData.DepCode">
  86. </el-input>
  87. </el-form-item>
  88. <el-form-item label="部门名称" prop="DepName">
  89. <el-input placeholder="请输入内容" v-model="upData.DepName">
  90. </el-input>
  91. </el-form-item>
  92. <el-form-item label="所属公司" prop="CompanyId">
  93. <el-select v-model="upData.CompanyId" filterable placeholder="请选择所属公司" @change="handleChange">
  94. <el-option v-for="item in optionsCompanys" :key="item.value" :label="item.label"
  95. :value="item.value">
  96. </el-option>
  97. </el-select>
  98. </el-form-item>
  99. <el-form-item label="上级部门" prop="ParentDepId">
  100. <el-select v-model="upData.ParentDepId" placeholder="请选择上级部门">
  101. <el-option v-for="item in optionsDepartment" :key="item.value" :label="item.label"
  102. :value="item.value">
  103. </el-option>
  104. </el-select>
  105. </el-form-item>
  106. <el-form-item label="备 注" prop="Remark">
  107. <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="upData.Remark"></el-input>
  108. </el-form-item>
  109. </el-form>
  110. </div>
  111. <span slot="footer" class="dialog-footer">
  112. <el-button @click="upDepVisible = false">取 消</el-button>
  113. <el-button type="primary" @click="upDateBtn">确 定</el-button>
  114. </span>
  115. </el-dialog>
  116. </div>
  117. </template>
  118. <script>
  119. import { co, el } from '@fullcalendar/core/internal-common';
  120. import { del } from 'vue';
  121. export default {
  122. data() {
  123. return {
  124. tableDatas: [],
  125. tableData: [],
  126. currentPage: 1, // 当前页码
  127. pageSize: 15,// 每页的数据条数
  128. input: '',
  129. token: '',
  130. userId: 0,
  131. addDepVisible: false,
  132. upDepVisible: false,
  133. upData: {
  134. Id: 0,
  135. CompanyId: '',
  136. DepCode: "",
  137. DepName: "",
  138. ParentDepId: 0,
  139. Remark: ""
  140. },
  141. //添加参数
  142. addData: {
  143. CompanyId: '',
  144. DepCode: "",
  145. DepName: "",
  146. ParentDepId: 0,
  147. CreateUserId: this.userId,
  148. Remark: ""
  149. },
  150. rules: {
  151. DepCode: [
  152. { required: true, message: '请输入部门Code', trigger: 'blur' },
  153. ],
  154. DepName: [
  155. { required: true, message: '请输入部门名称', trigger: 'blur' },
  156. ],
  157. CompanyId: [
  158. { required: true, message: '请选择所属公司', trigger: 'change' }
  159. ],
  160. },
  161. optionsDepartment: [],
  162. ParentDepId: '',
  163. optionsCompanys: [],
  164. CompanyId: ''
  165. }
  166. },
  167. methods: {
  168. //每页条数改变时触发 选择一页显示多少行
  169. handleSizeChange(val) {
  170. this.currentPage = 1;
  171. this.pageSize = val;
  172. },
  173. //当前页改变时触发 跳转其他页
  174. handleCurrentChange(val) {
  175. this.currentPage = val;
  176. },
  177. Department() {
  178. var url = "http://localhost:5256/api/System/QueryDepartmentList"
  179. var that = this
  180. this.$axios({
  181. method: 'post',
  182. url: url,
  183. headers: {
  184. Authorization: 'Bearer ' + this.token
  185. },
  186. data: {
  187. portType: 1,
  188. CompanyId: 0
  189. }
  190. }).then(function (res) {
  191. debugger
  192. console.log(res)
  193. if (res.data.code == 200) {
  194. debugger
  195. debugger
  196. that.tableDatas = res.data.data;
  197. that.tableData = that.tableDatas
  198. that.tableDatas.forEach(function (item, index) {
  199. that.optionsDepartment.push({
  200. value: item.id,
  201. label: item.depName
  202. });
  203. });
  204. }
  205. })
  206. },
  207. //公司下拉框绑定
  208. company() {
  209. var url = "http://localhost:5256/api/System/getCompanyList"
  210. var that = this
  211. this.$axios({
  212. method: 'post',
  213. url: url,
  214. headers: {
  215. Authorization: 'Bearer ' + this.token
  216. },
  217. data: {
  218. portType: 1,
  219. }
  220. }).then(function (res) {
  221. console.log(res)
  222. debugger
  223. if (res.data.code == 200) {
  224. debugger
  225. res.data.data.forEach(function (item, index) {
  226. that.optionsCompanys.push({
  227. value: item.id,
  228. label: item.companyName
  229. });
  230. });
  231. }
  232. })
  233. },
  234. handleChange(event) {
  235. debugger
  236. var comId = event;
  237. const that = this;
  238. that.optionsDepartment = [{
  239. value: 0,
  240. label: '请选择上级部门'
  241. }]
  242. that.tableDatas.forEach(function (item, index) {
  243. if (item.companyId == comId && comId != 0) {
  244. that.optionsDepartment.push({
  245. value: item.id,
  246. label: item.depName
  247. });
  248. } else if (comId == 0) {
  249. that.optionsDepartment.push({
  250. value: item.id,
  251. label: item.depName
  252. });
  253. }
  254. });
  255. },
  256. Inquireclick() {
  257. var newarr = [];
  258. if (this.input == "") {
  259. newarr = this.tableData;
  260. } else {
  261. for (var i = 0; i < this.tableData.length; i++) {
  262. if (this.tableData[i].depName.indexOf(this.input) != -1) {
  263. newarr.push(this.tableData[i]);
  264. }
  265. if (this.tableData[i].companyName.indexOf(this.input) != -1) {
  266. newarr.push(this.tableData[i]);
  267. }
  268. }
  269. }
  270. this.tableDatas = newarr;
  271. },
  272. //#region 修改操作
  273. upDate(index, row) {
  274. debugger
  275. this.upDepVisible = true;
  276. this.upData.Id = row.id
  277. this.upData.CompanyId = row.companyId
  278. this.upData.DepCode = row.depCode
  279. this.upData.DepName = row.depName
  280. this.upData.ParentDepId = row.parentDepId
  281. this.upData.Remark = row.remark
  282. },
  283. upDateBtn() {
  284. debugger
  285. var that = this
  286. this.$refs.upData.validate((valid) => {
  287. if (valid) {
  288. that.upData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  289. if (that.upData.DepName == "" || that.upData.DepName == undefined) {
  290. that.$message.error("部门名称不能为空");
  291. return
  292. }
  293. if (that.upData.DepCode == "") {
  294. that.$message.error("部门code不能为空");
  295. return
  296. }
  297. if (that.upData.CompanyId == 0) {
  298. that.$message.error("请选择所属公司");
  299. return
  300. }
  301. var url = "http://localhost:5256/api/System/EditDepartment"
  302. that.$axios({
  303. method: 'post',
  304. url: url,
  305. headers: {
  306. Authorization: 'Bearer ' + that.token
  307. },
  308. data: that.upData
  309. }).then(function (res) {
  310. console.log(res)
  311. debugger
  312. if (res.data.code == 200) {
  313. that.$message({
  314. message: '修改成功',
  315. type: 'success'
  316. });
  317. that.upDepVisible = false;
  318. that.Department();
  319. } else {
  320. that.$message.error('修改失败!');
  321. }
  322. })
  323. } else {
  324. this.$message.error('请完善信息在保存!');
  325. return false;
  326. }
  327. })
  328. },
  329. //关闭修改框
  330. handleClose(done) {
  331. done();
  332. },
  333. //#endregion
  334. del(index, row) {
  335. debugger
  336. this.$confirm('此操作将取消订单, 是否继续?', '提示', {
  337. confirmButtonText: '确定',
  338. cancelButtonText: '取消',
  339. type: 'warning'
  340. }).then(() => {
  341. var url = "http://localhost:5256/api/System/DelDepartment"
  342. var that = this
  343. this.$axios({
  344. method: 'post',
  345. url: url,
  346. headers: {
  347. Authorization: 'Bearer ' + this.token
  348. },
  349. data: {
  350. Id: row.id,
  351. }
  352. }).then(function (res) {
  353. console.log(res)
  354. debugger
  355. if (res.data.code == 200) {
  356. that.$message({
  357. type: 'success',
  358. message: '删除成功!'
  359. });
  360. that.Department();
  361. } else {
  362. that.$message.error("删除失败,请稍后重试");
  363. }
  364. })
  365. }).catch(() => {
  366. this.$message({
  367. type: 'info',
  368. message: '操作已取消!'
  369. });
  370. });
  371. },
  372. //#region 添加
  373. addDepartment() {
  374. this.addDepVisible = true
  375. },
  376. Addbtn() {
  377. debugger
  378. this.$refs.addData.validate((valid) => {
  379. if (valid) {
  380. var that = this
  381. that.addData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  382. if (that.addData.DepName == "" || that.addData.DepName == undefined) {
  383. that.$message.error("部门名称不能为空");
  384. return
  385. }
  386. if (that.addData.DepCode == "") {
  387. that.$message.error("部门code不能为空");
  388. return
  389. }
  390. if (that.addData.CompanyId == 0) {
  391. that.$message.error("请选择所属公司");
  392. return
  393. }
  394. var url = "http://localhost:5256/api/System/AddDepartment"
  395. that.$axios({
  396. method: 'post',
  397. url: url,
  398. headers: {
  399. Authorization: 'Bearer ' + that.token
  400. },
  401. data: that.addData
  402. }).then(function (res) {
  403. console.log(res)
  404. debugger
  405. if (res.data.code == 200) {
  406. that.$message({
  407. message: '添加成功!',
  408. type: 'success'
  409. });
  410. that.addDepVisible = false;
  411. that.Department();
  412. that.addData.CompanyId = 0;
  413. that.addData.DepCode = "";
  414. that.addData.DepName = "";
  415. that.addData.ParentDepId = 0;
  416. that.addData.CreateUserId = this.userId;
  417. that.addData.Remark = "";
  418. } else {
  419. that.$message.error('添加失败!');
  420. }
  421. })
  422. } else {
  423. this.$message.error('请完善信息在保存!');
  424. return false;
  425. }
  426. })
  427. },
  428. //#endregion
  429. },
  430. mounted() {
  431. debugger
  432. this.token = JSON.parse(localStorage.getItem('userinif')).token;
  433. this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  434. console.log(this.token)
  435. this.Department();
  436. this.company();
  437. }
  438. }
  439. </script>
  440. <style>
  441. .communal-list {
  442. background-color: #fff;
  443. padding: 10px;
  444. box-shadow: 0 0 5px #0005;
  445. border-radius: 10px;
  446. }
  447. .communal-title {
  448. display: flex;
  449. font-size: 17px;
  450. font-weight: 600;
  451. color: #555;
  452. margin-top: 8px;
  453. margin-bottom: 2px;
  454. justify-content: space-between;
  455. align-items: center;
  456. }
  457. .communal-box {
  458. display: flex;
  459. }
  460. .communal-box>button {
  461. margin-left: 10px;
  462. padding: 8px 20px;
  463. }
  464. </style>