people_fireStation.vue 11 KB

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