people_fireStation.vue 15 KB

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