people_fireStation.vue 13 KB

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