people_fireStation.vue 16 KB

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