people_fireStation.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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">
  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. let ids = localStorage.getItem("fireId")
  396. if (ids) {
  397. this.fireStationId = ids
  398. }
  399. },
  400. onShow() {
  401. if (this.$route.query.addId) {
  402. this.getAllFire()
  403. this.getbackid()
  404. // console.log(options, 'options')
  405. this.resultId = this.$route.query.addId
  406. if (this.resultId === '2') {
  407. this.tomole = '添加负责人'
  408. } else if (this.resultId === '1') {
  409. this.tomole = '添加值班人'
  410. } else {
  411. this.tomole = '添加人员信息'
  412. }
  413. // console.log(this.$route.query, 'query'); // 输出传递的参数值
  414. } else {
  415. return
  416. }
  417. },
  418. computed: {
  419. getDuty() {
  420. return (num) => {
  421. if (num === '1') {
  422. return '值班人';
  423. } else if (num === '2') {
  424. return '负责人';
  425. } else {
  426. return '普通人员';
  427. }
  428. };
  429. }
  430. }
  431. }
  432. </script>
  433. <style>
  434. /deep/ .typeStyle {
  435. width: 650rpx !important;
  436. }
  437. /deep/ .antherStyle {
  438. width: 630rpx;
  439. height: 100rpx;
  440. margin-left: 20rpx;
  441. }
  442. /deep/ .antherBtn {
  443. width: 200rpx;
  444. height: 50rpx;
  445. margin-bottom: 30rpx;
  446. background-color: #4DB1B6;
  447. color: white;
  448. text-align: center;
  449. line-height: 50rpx;
  450. font-size: 30rpx;
  451. border-radius: 20rpx;
  452. }
  453. .tableBox {
  454. width: 90%;
  455. height: auto;
  456. margin: 20rpx auto;
  457. margin-left: 40rpx;
  458. /* background-color: aqua; */
  459. }
  460. .custom-table {
  461. border-collapse: collapse;
  462. /* 合并边框 */
  463. }
  464. .custom-table th,
  465. .custom-table td {
  466. /* width: 39.5%; */
  467. border: 1px solid #4DB1B6;
  468. /* 添加边框样式 */
  469. padding: 8px;
  470. /* 设置单元格内边距 */
  471. }
  472. .aTd {
  473. /* width: 60%; */
  474. }
  475. .editBtn {
  476. width: 100rpx;
  477. height: 60rpx;
  478. background-color: #4DB1B6;
  479. color: white;
  480. text-align: center;
  481. line-height: 60rpx;
  482. border-radius: 10rpx;
  483. font-size: 20rpx;
  484. margin-bottom: 10rpx;
  485. margin-right: 10rpx;
  486. }
  487. .modalBox {
  488. width: 600rpx;
  489. height: 880rpx;
  490. }
  491. .insides {
  492. width: 400rpx;
  493. height: 100rpx;
  494. border: 1px solid #4DB1B6;
  495. }
  496. .useBox {
  497. display: flex;
  498. justify-content: space-around;
  499. align-items: center;
  500. margin-top: 20rpx;
  501. }
  502. .erroring {
  503. color: red;
  504. font-size: 20rpx;
  505. }
  506. .circleBtn {
  507. width: 100rpx;
  508. height: 100rpx;
  509. border-radius: 50%;
  510. font-size: 90rpx;
  511. text-align: center;
  512. line-height: 100rpx;
  513. color: white;
  514. background-color: #4EB0B5;
  515. position: absolute;
  516. top: 1300rpx;
  517. left: 590rpx;
  518. }
  519. .cardBox {
  520. width: 650rpx;
  521. margin: 30rpx auto;
  522. border-radius: 30rpx;
  523. }
  524. </style>