user.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <template>
  2. <view class="m_right">
  3. <view class="m_right_hander">
  4. <button size="mini" class="m_btn_red" @click="addUser()">添加用户</button>
  5. </view>
  6. <view class="m_right_container">
  7. <table style="width: 100%;border: 1px solid #DDDDDD;border-collapse: collapse">
  8. <thead class="m-table-hander">
  9. <tr>
  10. <!-- <th>用户名</th> -->
  11. <th>姓名</th>
  12. <th>班级</th>
  13. <th>学号</th>
  14. <th>电话</th>
  15. <th>ilab账户</th>
  16. <th>注册时间</th>
  17. <th>分数</th>
  18. <th>修改信息</th>
  19. <th>删除</th>
  20. </tr>
  21. </thead>
  22. <tbody>
  23. <tr v-for="(dataUser,dataUserI) in dataUsers_all" :key="dataUserI">
  24. <!-- <th style="color: #EA252C;">{{dataUser.IlabAccount}}</th> -->
  25. <th>{{dataUser.Name}}</th>
  26. <th>{{dataUser.Class}}</th>
  27. <th>{{dataUser.StudentID}}</th>
  28. <th>{{dataUser.PhoneNum}}</th>
  29. <th>{{dataUser.IlabAccount}}</th>
  30. <th>{{dataUser.SignTime}}</th>
  31. <th>{{dataUser.TotalScore}}</th>
  32. <th class="btn_bg"><button type="default" size="mini" class="m_edit" @click="modify(dataUser)">修改</button></th>
  33. <th class="btn_bg"><button type="default" size="mini" class="m_delete" @click="deleteUser(dataUser)">删除</button></th>
  34. </tr>
  35. </tbody>
  36. </table>
  37. </view>
  38. <view class="m_right_footer">
  39. <view class="m_paging">
  40. <text class="m_paging_item m_paging_upper" v-show="bShowLastPageBtn" @click="last()">上一页</text>
  41. <!-- <text class="m_paging_item" :key="i" v-for="i in pageTotalNum" @click="paging(i)" :class="i==index?'p_act':''"> -->
  42. <text class="m_paging_item" :key="i" v-for="i in pageTotalNum" @click="paging(i)" :class="i==currentPage?'p_act':''">
  43. {{i}}
  44. </text>
  45. <text class="m_paging_item m_paging_lower" v-show="bShowNextPageBtn" @click="next()">下一页</text>
  46. </view>
  47. </view>
  48. <popForm ref="popForm"></popForm>
  49. <popAlert ref="popAlert"></popAlert>
  50. </view>
  51. </template>
  52. <script>
  53. import popForm from '@/components/popForm.vue'
  54. import popAlert from '@/components/popAlert.vue'
  55. export default {
  56. name: "manager_user",
  57. components: {
  58. popForm,
  59. popAlert,
  60. },
  61. data() {
  62. return {
  63. pageTotalNum:1,
  64. currentPage:1,
  65. totalItem:2,
  66. dataUsers_all: [],
  67. bShowLastPageBtn:false,
  68. bShowNextPageBtn:false,
  69. }
  70. },
  71. methods: {
  72. paging(i) {
  73. // console.log('index=',i)
  74. uni.showLoading({
  75. title: '加载中'
  76. });
  77. let fromIndex = this.totalItem*(i-1);
  78. let toIndex = fromIndex+this.totalItem;
  79. let data = {
  80. "UserID": mydata_userInfo.userID,
  81. "BeginNum": fromIndex, //用户数组索引
  82. "EndNum": toIndex //用户数组索引结束
  83. }
  84. console.log('data===',data)
  85. uni.request({
  86. header: {
  87. 'Content-Type': 'application/json;charset=UTF-8'
  88. },
  89. url: mydata_api + '/backstage/getalluser',
  90. method: 'POST',
  91. data: data,
  92. dataType: 'json',
  93. success: (res) => {
  94. //100成功
  95. if (res.data.Code == 100) {
  96. console.log("请求全部用户res", res);
  97. this.dataUsers_all = res.data.Users;
  98. this.pageTotalNum = Math.ceil(res.data.AllNumOfList/this.totalItem);
  99. this.currentPage = i;
  100. this.showNextOrLastPageBtn();
  101. this.setTotalScore();
  102. }
  103. //200失败
  104. else {
  105. console.log('suc200', res);
  106. }
  107. uni.hideLoading();
  108. },
  109. fail: (res) => {
  110. console.log("请求失败****");
  111. uni.hideLoading();
  112. }
  113. });
  114. },
  115. initPage() {
  116. this.paging(1);
  117. },
  118. //分数合并
  119. setTotalScore() {
  120. for (let i = 0; i < this.dataUsers_all.length; i++) {
  121. let totalScore = 0;
  122. for (let j = 0; j < this.dataUsers_all[i].UserScore.length; j++) {
  123. let ascore = Number(this.dataUsers_all[i].UserScore[j]);
  124. if (ascore) {
  125. totalScore += ascore;
  126. }
  127. }
  128. this.dataUsers_all[i].TotalScore = totalScore;
  129. }
  130. },
  131. last()
  132. {
  133. this.currentPage--;
  134. this.paging(this.currentPage);
  135. },
  136. next()
  137. {
  138. this.currentPage++;
  139. this.paging(this.currentPage);
  140. },
  141. showNextOrLastPageBtn()
  142. {
  143. // if((this.pageTotalNum-this.totalItem)>0)
  144. // {
  145. // this.bShowLastPageBtn = false;
  146. // this.bShowNextPageBtn = false;
  147. // // console.log('0000')
  148. // }
  149. // else
  150. if(this.pageTotalNum==this.currentPage)
  151. {
  152. this.bShowLastPageBtn = true;
  153. this.bShowNextPageBtn = false;
  154. // console.log('11111')
  155. }
  156. else if(1==this.currentPage)
  157. {
  158. this.bShowLastPageBtn = false;
  159. this.bShowNextPageBtn = true;
  160. // console.log('2222')
  161. }
  162. else
  163. {
  164. this.bShowLastPageBtn = true;
  165. this.bShowNextPageBtn = true;
  166. // console.log('333333')
  167. }
  168. if(this.pageTotalNum==1){
  169. this.bShowLastPageBtn = false;
  170. this.bShowNextPageBtn = false;
  171. // console.log('444444')
  172. }
  173. },
  174. addUser(){
  175. this.$refs.popForm.isShow(true);
  176. this.$refs.popForm.setTitle('添加用户');
  177. let _self = this;
  178. let callback = function(content_arr){
  179. let data = {
  180. "IlabAccount":content_arr[0].input,
  181. "UserID" : content_arr[1].input,
  182. "SetUserID":content_arr[2].input,
  183. "Name":content_arr[3].input,
  184. "School":content_arr[4].input,
  185. "Department":content_arr[5].input,
  186. "Profession":content_arr[6].input,
  187. "Class":content_arr[7].input,
  188. "StudentID":content_arr[8].input,
  189. "Post":content_arr[9].input,
  190. "PhoneNum":content_arr[10].input,
  191. "Email":content_arr[11].input,
  192. "Nation":content_arr[12].input,
  193. "PoliticsStatus":content_arr[13].input,
  194. "NativePlace":content_arr[14].input,
  195. "Certificate":content_arr[15].input,
  196. "CertificateNum":content_arr[16].input,
  197. }
  198. // console.log('data===',data)
  199. uni.showLoading({
  200. title: '上传中'
  201. });
  202. uni.request({
  203. header: {
  204. 'Content-Type': 'application/json;charset=UTF-8'
  205. },
  206. url: mydata_api + '/backstage/addusers',
  207. method: 'POST',
  208. data: data,
  209. dataType: 'json',
  210. success: (res) => {
  211. //100成功
  212. if (res.data.Code == 100) {
  213. console.log("添加用户成功", res);
  214. _self.paging(_self.currentPage);
  215. }
  216. //200失败
  217. else {
  218. console.log('添加用户成功失败200', res);
  219. }
  220. uni.hideLoading();
  221. },
  222. fail: (res) => {
  223. console.log("添加用户成功失败");
  224. uni.hideLoading();
  225. }
  226. });
  227. };
  228. this.$refs.popForm.setContent([
  229. {
  230. 'name':'Ilab账号',
  231. 'input':'',
  232. 'type' :'text'
  233. },
  234. {
  235. 'name':'设置用户',
  236. 'input':mydata_userInfo.userID,
  237. 'type' :'text'
  238. },
  239. {
  240. 'name':'被设置用户ID',
  241. 'input':'',
  242. 'type' :'text'
  243. },
  244. {
  245. 'name':'姓名',
  246. 'input':'',
  247. 'type' :'text'
  248. },
  249. {
  250. 'name':'学校',
  251. 'input':'',
  252. 'type' :'text'
  253. },
  254. {
  255. 'name':'院系',
  256. 'input':'',
  257. 'type' :'text'
  258. },
  259. {
  260. 'name':'专业',
  261. 'input':'',
  262. 'type' :'text'
  263. },
  264. {
  265. 'name':'班级',
  266. 'input':'',
  267. 'type' :'text'
  268. },
  269. {
  270. 'name':'学号',
  271. 'input':'',
  272. 'type' :'text'
  273. },
  274. {
  275. 'name':'Post',
  276. 'input':'',
  277. 'type' :'text'
  278. },
  279. {
  280. 'name':'职务',
  281. 'input':'',
  282. 'type' :'text'
  283. },
  284. {
  285. 'name':'电话',
  286. 'input':'',
  287. 'type' :'text'
  288. },
  289. {
  290. 'name':'邮箱',
  291. 'input':'',
  292. 'type' :'text'
  293. },
  294. {
  295. 'name':'民族',
  296. 'input':'',
  297. 'type' :'text'
  298. },
  299. {
  300. 'name':'政治面貌',
  301. 'input':'',
  302. 'type' :'text'
  303. },
  304. {
  305. 'name':'籍贯',
  306. 'input':'',
  307. 'type' :'text'
  308. },
  309. {
  310. 'name':'证件类型',
  311. 'input':'',
  312. 'type' :'text'
  313. },
  314. {
  315. 'name':'证件号码',
  316. 'input':'',
  317. 'type' :'text'
  318. }
  319. ],callback);
  320. },
  321. modify(dataUser)
  322. {
  323. this.$refs.popForm.isShow(true);
  324. this.$refs.popForm.setTitle('修改用户信息');
  325. let _self = this;
  326. let callback = function(content_arr){
  327. let data = {
  328. "UserID":mydata_userInfo.userID,
  329. "SetUserID" : dataUser.Id,
  330. "Name":content_arr[0].input,
  331. "School":dataUser.School,
  332. "Department":dataUser.Department,
  333. "Profession":dataUser.Profession,
  334. "Class":content_arr[1].input,
  335. "StudentID":content_arr[2].input,
  336. "Post":dataUser.Post,
  337. "PhoneNum":content_arr[3].input,
  338. "Email":dataUser.Email,
  339. "Nation":dataUser.Nation,
  340. "PoliticsStatus":dataUser.PoliticsStatus,
  341. "NativePlace":dataUser.NativePlace,
  342. "Certificate":dataUser.Certificate,
  343. "CertificateNum":dataUser.CertificateNum,
  344. }
  345. uni.showLoading({
  346. title: '上传中'
  347. });
  348. uni.request({
  349. header: {
  350. 'Content-Type': 'application/json;charset=UTF-8'
  351. },
  352. url: mydata_api + '/user/setuserinfo',
  353. method: 'POST',
  354. data: data,
  355. dataType: 'json',
  356. success: (res) => {
  357. //100成功
  358. if (res.data.Code == 100) {
  359. console.log("修改用户信息成功", res);
  360. _self.paging(_self.currentPage);
  361. }
  362. //200失败
  363. else {
  364. console.log('修改用户信息失败200', res);
  365. }
  366. uni.hideLoading();
  367. },
  368. fail: (res) => {
  369. console.log("修改用户信息失败");
  370. uni.hideLoading();
  371. }
  372. });
  373. };
  374. this.$refs.popForm.setContent([
  375. {
  376. 'name':'姓名',
  377. 'input':dataUser.Name,
  378. 'type' :'text'
  379. },
  380. {
  381. 'name':'班级',
  382. 'input':dataUser.Class,
  383. 'type' :'text'
  384. },
  385. {
  386. 'name':'学号',
  387. 'input':dataUser.StudentID,
  388. 'type' :'text'
  389. },
  390. {
  391. 'name':'电话',
  392. 'input':dataUser.PhoneNum,
  393. 'type' :'text'
  394. }
  395. ],callback);
  396. },
  397. deleteUser(dataUser)
  398. {
  399. this.$refs.popAlert.isShow(true);
  400. this.$refs.popAlert.setTitle('提示');
  401. let _self = this;
  402. let callback = function(){
  403. let data = {
  404. "UserID":mydata_userInfo.userID,
  405. "DeleteUserID" : dataUser.Id
  406. }
  407. uni.showLoading({
  408. title: '上传中'
  409. });
  410. uni.request({
  411. header: {
  412. 'Content-Type': 'application/json;charset=UTF-8'
  413. },
  414. url: mydata_api + '/backstage/deleteuser',
  415. method: 'POST',
  416. data: data,
  417. dataType: 'json',
  418. success: (res) => {
  419. //100成功
  420. if (res.data.Code == 100) {
  421. console.log("删除用户成功", res);
  422. _self.paging(_self.currentPage);
  423. }
  424. //200失败
  425. else {
  426. console.log('删除用户失败200', res);
  427. }
  428. uni.hideLoading();
  429. },
  430. fail: (res) => {
  431. console.log("删除用户失败");
  432. uni.hideLoading();
  433. }
  434. });
  435. }
  436. this.$refs.popAlert.setContent('是否删除用户',callback);
  437. },
  438. }
  439. }
  440. </script>
  441. <style lang="scss">
  442. .m_right {
  443. width: 100%;
  444. margin-top: 5rpx;
  445. padding: 0 150rpx;
  446. background-color: #fff;
  447. box-shadow: 3px 0px 6px 0px rgba(0, 0, 0, 0.1);
  448. .m_right_hander {
  449. text-align: right;
  450. height: 250rpx;
  451. position: relative;
  452. .m_btn_red {
  453. position: absolute;
  454. height: 80rpx;
  455. line-height: 80rpx;
  456. padding: 0 40rpx;
  457. right: 0;
  458. top: 50%;
  459. transform: translateY(-50%);
  460. background: #EA252C;
  461. color: #fff;
  462. }
  463. }
  464. }
  465. tbody tr {
  466. // border-top: 2rpx solid #DDDDDD !important;
  467. border: 2rpx solid #DDDDDD !important;
  468. }
  469. th {
  470. border: 2rpx solid #DDDDDD !important;
  471. }
  472. tbody tr th {
  473. font-weight: 400 !important;
  474. height: 140rpx;
  475. line-height: 140rpx;
  476. border: 2rpx solid #DDDDDD !important;
  477. }
  478. // tbody tr:hover {
  479. // // color: #fff;
  480. // background: #FDEBEC;
  481. // // opacity: 0.08;
  482. // }
  483. .center{
  484. display: flex;
  485. justify-content: center;
  486. align-items: center;
  487. }
  488. .m-table-hander {
  489. background-color: #FFF8F7;
  490. height: 140rpx;
  491. line-height: 140rpx;
  492. font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
  493. font-weight: bold;
  494. }
  495. .btn_bg{
  496. // border: 1rpx solid #DDDDDD;
  497. // display: flex;
  498. // justify-content: center;
  499. // align-items: center;
  500. }
  501. .m_edit {
  502. // position: relative;
  503. // top: 50%;
  504. // left: 50%;
  505. // transform: translate(-50%, -50%);
  506. background: rgb(67, 127, 250);
  507. color: rgb(255, 255, 255);
  508. // width: 60%;
  509. }
  510. .m_delete {
  511. background: rgb(234, 37, 44);
  512. color: rgb(255, 255, 255);
  513. // width: 60%;
  514. }
  515. .m_right_footer {
  516. margin-top: 80rpx;
  517. }
  518. .m_paging {
  519. text-align: right;
  520. .m_paging_item {
  521. padding: 10rpx 18rpx;
  522. border: 1rpx solid #DDDDDD;
  523. border-radius: 8rpx;
  524. margin-right: 10rpx;
  525. }
  526. .p_act {
  527. background: #EA252C;
  528. color: #fff;
  529. border: inherit;
  530. }
  531. }
  532. .m_paging_item:hover {
  533. background: #EA252C;
  534. color: #fff;
  535. border: inherit;
  536. }
  537. .m_act1 {
  538. color: #FF0019;
  539. }
  540. </style>