people_fireStation.vue 14 KB

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