people_fireStation.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <template>
  2. <view style="position: relative;">
  3. <navInfo :title="'编辑人员'"></navInfo>
  4. <view class="bgTopImg" style="height:200rpx;">
  5. <image slot="right" class="bgTopImg"></image>
  6. </view>
  7. <div class="cardBox">
  8. <uni-card v-for="item in tableList" style="border: 2rpx solid #4DB1B6;">
  9. <div style="display: flex;justify-content: space-between;align-items: center;">
  10. <div>
  11. <text>姓名:{{item.empName}}</text><br>
  12. <text>电话:{{ item.mobile }}</text><br>
  13. <text>身份证号:{{item.idcardno}}</text><br>
  14. <text>职务:{{getDuty(item.duty)}}</text>
  15. </div>
  16. <div style="display: flex;justify-content: space-around;align-items: center;">
  17. <button @click="delUser(item)" class="editBtn" style="background-color: red;">删除</button>
  18. <button @click="editUser(item)" class="editBtn">编辑</button>
  19. </div>
  20. </div>
  21. </uni-card>
  22. </div>
  23. <!-- 新增的人员表单项 -->
  24. <div v-for="(person, index) in membersList" :key="index"
  25. style="border-bottom: 1px solid black;margin-top: 100rpx;">
  26. <u--form ref="forms">
  27. <u-form-item class="typeStyle" :prop="'name' + (index + 1)">
  28. <p style="width: 150rpx;margin-left: 20rpx;">姓名</p>
  29. <u-input v-model="person.name" id="nameId" @change="nameBlur" :placeholder="'请输入姓名'" />
  30. <span class="erroring" v-if="nameRules">请输入名称</span>
  31. </u-form-item>
  32. <u-form-item class="typeStyle" :prop="'age' + (index + 1)">
  33. <p style="width: 150rpx;margin-left: 20rpx;">身份证号</p>
  34. <u-input @change="userBlur" v-model="person.userNum" :placeholder="'请输入身份证号'" />
  35. <span class="erroring" v-if="userRules">身份证号有误</span>
  36. </u-form-item>
  37. <!-- 其他人员信息字段 -->
  38. <u-form-item class="typeStyle" :prop="'age' + (index + 1)">
  39. <p style="width: 150rpx;margin-left: 20rpx;">电话号</p>
  40. <u-input v-model="person.phone" @change="phoneBlur" :placeholder="'请输入电话号'" />
  41. <span class="erroring" v-if="phoneRules">电话号有误</span>
  42. </u-form-item>
  43. <!-- <u-form-item class="typeStyle" :prop="'age' + (index + 1)">
  44. <p style="width: 150rpx;margin-left: 20rpx;">人员类型</p>
  45. <u-input v-model="person.worker" :placeholder="'请输入人员类型'" />
  46. </u-form-item> -->
  47. <u-form-item class="antherStyle">
  48. <p style="width: 150rpx;">人员类型</p>
  49. <uni-data-select v-model="person.power" :localdata="selectType" @change="change"></uni-data-select>
  50. </u-form-item>
  51. <u-form-item>
  52. <u-button type="primary" @click="addSure" class="antherBtn">提交</u-button>
  53. <u-button type="primary" @click="cleanList" class="antherBtn">取消</u-button>
  54. </u-form-item>
  55. </u--form>
  56. </div>
  57. <div>
  58. <u-popup :show="showModal" mode="center" @close="closeModal" :round="10">
  59. <view class="modalBox">
  60. <u--form labelPosition="left" :model="formbox" ref="uForm" style="width: 100%;">
  61. <u-form-item style="width: 400rpx;" label="姓名" prop="formbox.fname" borderBottom ref="item1">
  62. <u--input class="insides" v-model="formbox.fname" border="none"></u--input>
  63. </u-form-item>
  64. <u-form-item style="width: 350rpx;" label="电话号" prop="formbox.fphone" borderBottom ref="item1">
  65. <u--input class="insides" v-model="formbox.fphone" border="none"></u--input>
  66. </u-form-item>
  67. <u-form-item style="width: 490rpx;" label="人员类型" prop="formbox.fpower" borderBottom ref="item1">
  68. <uni-data-select v-model="formbox.fpower" :localdata="selectType"
  69. @change="change1"></uni-data-select>
  70. </u-form-item>
  71. <u-form-item style="width: 350rpx;" label="身份证号" prop="userInfo.fuserNum" borderBottom
  72. ref="item1">
  73. <u--input class="insides" v-model="formbox.fuserNum" border="none"></u--input>
  74. </u-form-item>
  75. <!-- <u-form-item style="width: 350rpx;" label="人员类型" prop="userInfo.fworker" borderBottom
  76. ref="item1">
  77. <u--input class="insides" v-model="formbox.fworker" border="none"></u--input>
  78. </u-form-item> -->
  79. </u--form>
  80. <div class="useBox">
  81. <button class="antherBtn" @click="makeSureEdit">确认修改</button>
  82. <button class="antherBtn" @click="showModal = false">取消</button>
  83. </div>
  84. </view>
  85. </u-popup>
  86. </div>
  87. <div>
  88. <u-popup :show="showDel" title="确认删除?" mode="center">
  89. <div style="width: 400rpx;height: 200rpx;margin: 20rpx 20rpx;">
  90. <p style="font-size: 35rpx;color: black;">是否删除该数据项?</p>
  91. <p style="font-size: 20rpx;color: gray;">确认删除?</p>
  92. <div style="display: flex;justify-content: space-around;align-items: center;margin-top: 40rpx;">
  93. <button class="antherBtn" @click="makeSureDel" style="background-color: red;">确认</button>
  94. <button class="antherBtn" @click="showDel = false">取消</button>
  95. </div>
  96. </div>
  97. </u-popup>
  98. </div>
  99. <div>
  100. <u-modal :show="show123" @confirm="confirm" @cancel="cancel" @close="close" asyncClose closeOnClickOverlay
  101. showCancelButton confirmColor="red" title="是否删除该数据项" content="确认删除?" ref="uModal"></u-modal>
  102. </div>
  103. <button @click="addNewPeople" class="circleBtn">+</button>
  104. </view>
  105. </template>
  106. <script>
  107. import {
  108. creatFirePeople,
  109. delFirePeople,
  110. outexcel,
  111. getMesbyid,
  112. getfirelist,
  113. getfirepage,
  114. editFirePeople,
  115. getuserfireid
  116. } from "../../../../api/peoplefire/index.js"
  117. import {
  118. getDict
  119. } from "../../../../api/dictName/index.js"
  120. import config from '@/config'
  121. const baseUrlImg = config.baseUrlImg
  122. import navInfo from '@/pagesA/components/my-nav/nav'
  123. export default {
  124. components: {
  125. navInfo
  126. },
  127. data() {
  128. return {
  129. membersList: [], //添加的人员数组
  130. resultId: '',
  131. value: 0,
  132. range: [{
  133. value: '2',
  134. text: "站长"
  135. },
  136. {
  137. value: '1',
  138. text: "值班人员"
  139. },
  140. {
  141. value: '0',
  142. text: "普通人员"
  143. },
  144. ],
  145. range1: [{
  146. value: '2',
  147. text: "负责人"
  148. },
  149. {
  150. value: '1',
  151. text: "值班人员"
  152. },
  153. {
  154. value: '0',
  155. text: "普通人员"
  156. },
  157. ],
  158. tomole: "添加人员",
  159. tableList: [], //显示的人员数组
  160. userId: '', //用户id
  161. smallFireId: '',
  162. fireStationId: 0, //消防站id
  163. showModal: false, //模态框开关
  164. formbox: {
  165. fname: '',
  166. fphone: '',
  167. fworker: '',
  168. fuserNum: '',
  169. fpower: '',
  170. },
  171. editPeopleId: '', //需要修改人员的id
  172. nameRules: false, //对name的正则验证
  173. userRules: false, //对身份证的正则验证
  174. phoneRules: false, //对电话的正则验证
  175. showDel: false,
  176. delId: '',
  177. show123: false,
  178. selectType: [], //选项
  179. }
  180. },
  181. methods: {
  182. getTypePeople() {
  183. getDict({
  184. pageNo: 1,
  185. pageSize: 10,
  186. dictType: "micro_emp_type"
  187. }).then(res => {
  188. this.selectType = res.data.list.map(item => {
  189. return {
  190. value: item.value,
  191. text: item.label
  192. }
  193. })
  194. })
  195. },
  196. addNewPeople() {
  197. const MAX_LENGTH = 1; // 假设你想限制数组最大长度为6
  198. if (this.membersList.length < MAX_LENGTH) {
  199. const newPerson = {
  200. name: '',
  201. userNum: '',
  202. phone: '',
  203. worker: '',
  204. power: '',
  205. // 其他字段
  206. };
  207. this.membersList.push(newPerson);
  208. } else {
  209. // 达到最大数量,给出提示或执行其他操作
  210. uni.showToast({
  211. title: '只支持一位添加',
  212. icon: 'none', // 图标类型,可选值:'success', 'loading', 'none'
  213. duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
  214. mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
  215. success() {
  216. // console.log('toast消息提示显示成功');
  217. },
  218. fail(err) {
  219. // console.error('toast消息提示显示失败', err);
  220. }
  221. });
  222. }
  223. },
  224. addSure() {
  225. if (this.$route.query.addId) {
  226. if (!this.userRules && !this.phoneRules && !this.nameRules) {
  227. creatFirePeople({
  228. duty: this.membersList[0].power,
  229. empName: this.membersList[0].name,
  230. // empType: this.membersList[0].worker,
  231. idcardno: this.membersList[0].userNum,
  232. microstationid: this.fireStationId - 0,
  233. mobile: this.membersList[0].phone,
  234. }).then(res => {
  235. if (res.data) {
  236. this.getAllFire()
  237. uni.showToast({
  238. title: '添加成功',
  239. icon: 'success', // 图标类型,可选值:'success', 'loading', 'none'
  240. duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
  241. mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
  242. success() {
  243. // console.log('toast消息提示显示成功');
  244. },
  245. fail(err) {
  246. // console.error('toast消息提示显示失败', err);
  247. }
  248. });
  249. this.membersList = []
  250. }
  251. })
  252. } else {
  253. uni.showToast({
  254. title: '请检查表单项',
  255. icon: 'none', // 图标类型,可选值:'success', 'loading', 'none'
  256. duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
  257. mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
  258. success() {
  259. // console.log('toast消息提示显示成功');
  260. },
  261. fail(err) {
  262. // console.error('toast消息提示显示失败', err);
  263. }
  264. });
  265. }
  266. } else {
  267. localStorage.setItem("empList", JSON.stringify(this.membersList))
  268. uni.navigateBack({
  269. delta: 1
  270. })
  271. }
  272. },
  273. change(e) {
  274. // console.log("e:", e);
  275. },
  276. change1(e) {
  277. // console.log("e:", e);
  278. },
  279. getbackid() {
  280. let x = localStorage.getItem('getUserInfo_key')
  281. x = JSON.parse(x)
  282. this.userId = x.data.userInfo.id
  283. getuserfireid({
  284. userId: this.userId
  285. }).then(res => {
  286. // console.log(res, 'userfire');
  287. })
  288. // console.log(x.data.userInfo.id, 'xxx');
  289. },
  290. getAllFire() {
  291. let num = 0
  292. if (this.$route.query.addId === '1') {
  293. num = '1'
  294. getfirepage({
  295. pageNo: 1,
  296. pageSize: 10,
  297. microstationid: this.fireStationId,
  298. duty: num
  299. }).then(res => {
  300. // console.log(res, '888');
  301. this.tableList = res.data.list
  302. })
  303. } else if (this.$route.query.addId === '2') {
  304. num = '2'
  305. getfirepage({
  306. pageNo: 1,
  307. pageSize: 10,
  308. microstationid: this.fireStationId,
  309. duty: num
  310. }).then(res => {
  311. // console.log(res, '888');
  312. this.tableList = res.data.list
  313. })
  314. } else if (this.$route.query.addId === '0') {
  315. num = '0'
  316. getfirepage({
  317. pageNo: 1,
  318. pageSize: 10,
  319. microstationid: this.fireStationId,
  320. duty: num
  321. }).then(res => {
  322. // console.log(res, '888');
  323. this.tableList = res.data.list
  324. })
  325. }
  326. },
  327. delUser(row) {
  328. this.show123 = true
  329. this.delId = row.id
  330. },
  331. makeSureDel() {
  332. },
  333. confirm() {
  334. delFirePeople(this.delId).then(res => {
  335. if (res.data) {
  336. uni.showToast({
  337. title: '删除成功',
  338. icon: 'success', // 图标类型,可选值:'success', 'loading', 'none'
  339. duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
  340. mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
  341. success() {
  342. // console.log('toast消息提示显示成功');
  343. },
  344. fail(err) {
  345. // console.error('toast消息提示显示失败', err);
  346. }
  347. });
  348. this.getAllFire()
  349. this.show123 = false
  350. }
  351. })
  352. },
  353. cancel() {
  354. this.show123 = false
  355. },
  356. close() {
  357. this.show123 = false
  358. },
  359. editUser(row) {
  360. this.editPeopleId = row.id
  361. getMesbyid({
  362. id: row.id
  363. }).then(res => {
  364. if (res.data) {
  365. this.formbox.fname = res.data.empName
  366. this.formbox.fphone = res.data.mobile
  367. this.formbox.fpower = res.data.duty
  368. // this.formbox.fworker = res.data.empType
  369. this.formbox.fuserNum = res.data.idcardno
  370. this.showModal = true
  371. }
  372. })
  373. },
  374. closeModal() {
  375. this.showModal = false
  376. },
  377. makeSureEdit() {
  378. editFirePeople({
  379. duty: this.formbox.fpower,
  380. empName: this.formbox.fname,
  381. // empType: this.formbox.fworker,
  382. id: this.editPeopleId,
  383. idcardno: this.formbox.fuserNum,
  384. microstationid: this.fireStationId - 0,
  385. mobile: this.formbox.fphone,
  386. }).then(res => {
  387. if (res.data) {
  388. this.showModal = false
  389. this.getAllFire()
  390. uni.showToast({
  391. title: '编辑成功',
  392. icon: 'success', // 图标类型,可选值:'success', 'loading', 'none'
  393. duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
  394. mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
  395. success() {
  396. // console.log('toast消息提示显示成功');
  397. },
  398. fail(err) {
  399. // console.error('toast消息提示显示失败', err);
  400. }
  401. });
  402. }
  403. // console.log(res, 'edit');
  404. })
  405. },
  406. // 对表单内name的正则判断
  407. nameBlur() {
  408. // console.log(this.membersList[0].name);
  409. if (this.membersList[0].name === '') {
  410. this.nameRules = true
  411. } else {
  412. this.nameRules = false
  413. }
  414. },
  415. userBlur() {
  416. const regex = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2]\d|3[0-1])\d{3}[\dxX]$/;
  417. if (regex.test(this.membersList[0].userNum)) {
  418. this.userRules = false
  419. } else {
  420. this.userRules = true
  421. }
  422. },
  423. phoneBlur() {
  424. const regex = /^1[3-9]\d{9}$/;
  425. if (regex.test(this.membersList[0].phone)) {
  426. this.phoneRules = false
  427. } else {
  428. this.phoneRules = true
  429. }
  430. },
  431. cleanList() {
  432. this.membersList = []
  433. let list = localStorage.getItem("empList")
  434. list = JSON.parse(list)
  435. if (list) {
  436. localStorage.removeItem('empList')
  437. }
  438. },
  439. // 读取本地缓存
  440. getGround() {
  441. let list = localStorage.getItem("empList")
  442. list = JSON.parse(list)
  443. if (list) {
  444. this.membersList = list
  445. } else {
  446. this.membersList = []
  447. }
  448. }
  449. },
  450. onLoad(options) {
  451. let ids = localStorage.getItem("fireId")
  452. if (ids) {
  453. this.fireStationId = ids
  454. }
  455. },
  456. onShow() {
  457. this.getTypePeople()
  458. this.getGround()
  459. if (this.$route.query.addId) {
  460. this.getAllFire()
  461. this.getbackid()
  462. // console.log(options, 'options')
  463. this.resultId = this.$route.query.addId
  464. if (this.resultId === '2') {
  465. this.tomole = '添加负责人'
  466. } else if (this.resultId === '1') {
  467. this.tomole = '添加值班人'
  468. } else {
  469. this.tomole = '添加人员信息'
  470. }
  471. // console.log(this.$route.query, 'query'); // 输出传递的参数值
  472. } else {
  473. return
  474. }
  475. },
  476. computed: {
  477. getDuty() {
  478. return (num) => {
  479. if (num === '1') {
  480. return '值班人';
  481. } else if (num === '2') {
  482. return '负责人';
  483. } else {
  484. return '普通人员';
  485. }
  486. };
  487. }
  488. }
  489. }
  490. </script>
  491. <style>
  492. /deep/ .typeStyle {
  493. width: 650rpx !important;
  494. }
  495. /deep/ .antherStyle {
  496. width: 630rpx;
  497. height: 100rpx;
  498. margin-left: 20rpx;
  499. }
  500. /deep/ .antherBtn {
  501. width: 200rpx;
  502. height: 50rpx;
  503. margin-bottom: 30rpx;
  504. background-color: #4DB1B6;
  505. color: white;
  506. text-align: center;
  507. line-height: 50rpx;
  508. font-size: 30rpx;
  509. border-radius: 20rpx;
  510. }
  511. .tableBox {
  512. width: 90%;
  513. height: auto;
  514. margin: 20rpx auto;
  515. margin-left: 40rpx;
  516. /* background-color: aqua; */
  517. }
  518. .custom-table {
  519. border-collapse: collapse;
  520. /* 合并边框 */
  521. }
  522. .custom-table th,
  523. .custom-table td {
  524. /* width: 39.5%; */
  525. border: 1px solid #4DB1B6;
  526. /* 添加边框样式 */
  527. padding: 8px;
  528. /* 设置单元格内边距 */
  529. }
  530. .aTd {
  531. /* width: 60%; */
  532. }
  533. .editBtn {
  534. width: 100rpx;
  535. height: 60rpx;
  536. background-color: #4DB1B6;
  537. color: white;
  538. text-align: center;
  539. line-height: 60rpx;
  540. border-radius: 10rpx;
  541. font-size: 20rpx;
  542. margin-bottom: 10rpx;
  543. margin-right: 10rpx;
  544. }
  545. .modalBox {
  546. width: 700rpx;
  547. height: 880rpx;
  548. }
  549. .insides {
  550. width: 400rpx;
  551. height: 100rpx;
  552. border: 1px solid #4DB1B6;
  553. }
  554. .useBox {
  555. display: flex;
  556. justify-content: space-around;
  557. align-items: center;
  558. margin-top: 20rpx;
  559. }
  560. .erroring {
  561. color: red;
  562. font-size: 20rpx;
  563. }
  564. .circleBtn {
  565. width: 100rpx;
  566. height: 100rpx;
  567. border-radius: 50%;
  568. font-size: 90rpx;
  569. text-align: center;
  570. line-height: 100rpx;
  571. color: white;
  572. background-color: #4EB0B5;
  573. position: absolute;
  574. top: 1300rpx;
  575. left: 590rpx;
  576. }
  577. .cardBox {
  578. width: 650rpx;
  579. margin: 30rpx auto;
  580. border-radius: 30rpx;
  581. }
  582. .u-form-item__body__left {
  583. width: 100rpx;
  584. }
  585. </style>