people_fireStation.vue 15 KB

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