people_fireStation.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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 newPerson = {
  158. name: '',
  159. userNum: '',
  160. phone: '',
  161. worker: "",
  162. power: "",
  163. // 其他字段
  164. };
  165. this.membersList.push(newPerson);
  166. },
  167. addSure() {
  168. creatFirePeople({
  169. duty: this.membersList[0].power,
  170. empName: this.membersList[0].name,
  171. empType: this.membersList[0].worker,
  172. idcardno: this.membersList[0].userNum,
  173. microstationid: this.fireStationId - 0,
  174. mobile: this.membersList[0].phone,
  175. }).then(res => {
  176. if (res.data) {
  177. this.getAllFire()
  178. uni.showToast({
  179. title: '添加成功',
  180. icon: 'success', // 图标类型,可选值:'success', 'loading', 'none'
  181. duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
  182. mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
  183. success() {
  184. console.log('toast消息提示显示成功');
  185. },
  186. fail(err) {
  187. console.error('toast消息提示显示失败', err);
  188. }
  189. });
  190. this.membersList = []
  191. }
  192. console.log(res, 'r11111');
  193. })
  194. // console.log(this.membersList, 'memberList');
  195. },
  196. change(e) {
  197. console.log("e:", e);
  198. },
  199. change1(e) {
  200. console.log("e:", e);
  201. },
  202. getbackid() {
  203. let x = localStorage.getItem('getUserInfo_key')
  204. x = JSON.parse(x)
  205. this.userId = x.data.userInfo.id
  206. getuserfireid({
  207. userId: this.userId
  208. }).then(res => {
  209. console.log(res, 'userfire');
  210. })
  211. // console.log(x.data.userInfo.id, 'xxx');
  212. },
  213. getAllFire() {
  214. let num = 0
  215. if (this.$route.query.addId === '1') {
  216. num = '1'
  217. getfirepage({
  218. pageNo: 1,
  219. pageSize: 10,
  220. microstationid: this.fireStationId,
  221. duty: num
  222. }).then(res => {
  223. // console.log(res, '888');
  224. this.tableList = res.data.list
  225. })
  226. } else if (this.$route.query.addId === '2') {
  227. num = '2'
  228. getfirepage({
  229. pageNo: 1,
  230. pageSize: 10,
  231. microstationid: this.fireStationId,
  232. duty: num
  233. }).then(res => {
  234. // console.log(res, '888');
  235. this.tableList = res.data.list
  236. })
  237. } else {
  238. num = '3'
  239. getfirepage({
  240. pageNo: 1,
  241. pageSize: 10,
  242. microstationid: this.fireStationId,
  243. duty: num
  244. }).then(res => {
  245. // console.log(res, '888');
  246. this.tableList = res.data.list
  247. })
  248. }
  249. },
  250. delUser(row) {
  251. delFirePeople(row.id).then(res => {
  252. if (res.data) {
  253. uni.showToast({
  254. title: '删除成功',
  255. icon: 'success', // 图标类型,可选值:'success', 'loading', 'none'
  256. duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
  257. mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
  258. success() {
  259. console.log('toast消息提示显示成功');
  260. },
  261. fail(err) {
  262. console.error('toast消息提示显示失败', err);
  263. }
  264. });
  265. this.getAllFire()
  266. }
  267. })
  268. },
  269. editUser(row) {
  270. this.editPeopleId = row.id
  271. getMesbyid({
  272. id: row.id
  273. }).then(res => {
  274. if (res.data) {
  275. this.formbox.fname = res.data.empName
  276. this.formbox.fphone = res.data.mobile
  277. this.formbox.fpower = res.data.duty
  278. this.formbox.fworker = res.data.empType
  279. this.formbox.fuserNum = res.data.idcardno
  280. this.showModal = true
  281. }
  282. })
  283. },
  284. closeModal() {
  285. this.showModal = false
  286. },
  287. makeSureEdit() {
  288. editFirePeople({
  289. duty: this.formbox.fpower,
  290. empName: this.formbox.fname,
  291. empType: this.formbox.fworker,
  292. id: this.editPeopleId,
  293. idcardno: this.formbox.fuserNum,
  294. microstationid: this.fireStationId - 0,
  295. mobile: this.formbox.fphone,
  296. }).then(res => {
  297. if (res.data) {
  298. this.showModal = false
  299. this.getAllFire()
  300. uni.showToast({
  301. title: '编辑成功',
  302. icon: 'success', // 图标类型,可选值:'success', 'loading', 'none'
  303. duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
  304. mask: false, // 是否显示透明蒙层,防止触摸穿透,默认值为 false
  305. success() {
  306. console.log('toast消息提示显示成功');
  307. },
  308. fail(err) {
  309. console.error('toast消息提示显示失败', err);
  310. }
  311. });
  312. }
  313. console.log(res, 'edit');
  314. })
  315. },
  316. // 对表单内name的正则判断
  317. nameBlur() {
  318. console.log(this.membersList[0].name);
  319. if (this.membersList[0].name === '') {
  320. this.nameRules = true
  321. } else {
  322. this.nameRules = false
  323. }
  324. },
  325. userBlur() {
  326. 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]$/;
  327. if (regex.test(this.membersList[0].userNum)) {
  328. this.userRules = false
  329. } else {
  330. this.userRules = true
  331. }
  332. },
  333. phoneBlur() {
  334. const regex = /^1[3-9]\d{9}$/;
  335. if (regex.test(this.membersList[0].phone)) {
  336. this.phoneRules = false
  337. } else {
  338. this.phoneRules = true
  339. }
  340. }
  341. },
  342. onLoad(options) {
  343. console.log(options, 'options')
  344. this.resultId = this.$route.query.addId
  345. if (this.resultId === '2') {
  346. this.tomole = '添加负责人'
  347. } else if (this.resultId === '1') {
  348. this.tomole = '添加值班人'
  349. } else {
  350. this.tomole = '添加人员信息'
  351. }
  352. let ids = localStorage.getItem("fireId")
  353. if (ids) {
  354. this.fireStationId = ids
  355. // console.log(this.fireStationId, 'fireid');
  356. }
  357. // console.log(this.$route.query, 'query'); // 输出传递的参数值
  358. },
  359. onShow() {
  360. this.getAllFire()
  361. this.getbackid()
  362. },
  363. computed: {
  364. getDuty() {
  365. return (num) => {
  366. if (num === '1') {
  367. return '值班人';
  368. } else if (num === '2') {
  369. return '负责人';
  370. } else {
  371. return '普通人员';
  372. }
  373. };
  374. }
  375. }
  376. }
  377. </script>
  378. <style>
  379. /deep/ .typeStyle {
  380. width: 650rpx !important;
  381. }
  382. /deep/ .antherStyle {
  383. width: 630rpx;
  384. height: 100rpx;
  385. margin-left: 20rpx;
  386. }
  387. /deep/ .antherBtn {
  388. width: 200rpx;
  389. height: 50rpx;
  390. margin-bottom: 30rpx;
  391. background-color: #4DB1B6;
  392. color: white;
  393. text-align: center;
  394. line-height: 50rpx;
  395. font-size: 30rpx;
  396. border-radius: 20rpx;
  397. }
  398. .tableBox {
  399. width: 90%;
  400. height: auto;
  401. margin: 20rpx auto;
  402. margin-left: 40rpx;
  403. /* background-color: aqua; */
  404. }
  405. .custom-table {
  406. border-collapse: collapse;
  407. /* 合并边框 */
  408. }
  409. .custom-table th,
  410. .custom-table td {
  411. /* width: 39.5%; */
  412. border: 1px solid #4DB1B6;
  413. /* 添加边框样式 */
  414. padding: 8px;
  415. /* 设置单元格内边距 */
  416. }
  417. .aTd {
  418. /* width: 60%; */
  419. }
  420. .editBtn {
  421. width: 100rpx;
  422. height: 60rpx;
  423. background-color: #4DB1B6;
  424. color: white;
  425. text-align: center;
  426. line-height: 60rpx;
  427. border-radius: 10rpx;
  428. font-size: 20rpx;
  429. margin-bottom: 10rpx;
  430. }
  431. .modalBox {
  432. width: 600rpx;
  433. height: 880rpx;
  434. }
  435. .insides {
  436. width: 400rpx;
  437. height: 100rpx;
  438. border: 1px solid #4DB1B6;
  439. }
  440. .useBox {
  441. display: flex;
  442. justify-content: space-around;
  443. align-items: center;
  444. margin-top: 20rpx;
  445. }
  446. .erroring {
  447. color: red;
  448. font-size: 20rpx;
  449. }
  450. </style>