Company.vue 22 KB

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