user.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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.currentPage)
  144. {
  145. this.bShowLastPageBtn = true;
  146. this.bShowNextPageBtn = false;
  147. // console.log('11111')
  148. }
  149. else if(1==this.currentPage)
  150. {
  151. this.bShowLastPageBtn = false;
  152. this.bShowNextPageBtn = true;
  153. // console.log('2222')
  154. }
  155. else
  156. {
  157. this.bShowLastPageBtn = true;
  158. this.bShowNextPageBtn = true;
  159. // console.log('333333')
  160. }
  161. if(this.pageTotalNum==1){
  162. this.bShowLastPageBtn = false;
  163. this.bShowNextPageBtn = false;
  164. // console.log('444444')
  165. }
  166. },
  167. addUser(){
  168. this.$refs.popForm.isShow(true);
  169. this.$refs.popForm.setTitle('添加用户');
  170. let _self = this;
  171. let callback = function(content_arr){
  172. let data = {
  173. "UserID":mydata_userInfo.userID,
  174. "Users":[
  175. {
  176. "IlabAccount":content_arr[0].input,
  177. "UserID" : content_arr[1].input,
  178. "SetUserID":content_arr[2].input,
  179. "Name":content_arr[3].input,
  180. "School":content_arr[4].input,
  181. "Department":content_arr[5].input,
  182. "Profession":content_arr[6].input,
  183. "Class":content_arr[7].input,
  184. "StudentID":Number(content_arr[8].input),
  185. "Post":content_arr[9].input,
  186. "PhoneNum":Number(content_arr[10].input),
  187. "Email":content_arr[11].input,
  188. "Nation":content_arr[12].input,
  189. "PoliticsStatus":content_arr[13].input,
  190. "NativePlace":content_arr[14].input,
  191. "Certificate":content_arr[15].input,
  192. "CertificateNum":content_arr[16].input
  193. }
  194. ]
  195. }
  196. // console.log('data===',data)
  197. uni.showLoading({
  198. title: '上传中'
  199. });
  200. uni.request({
  201. header: {
  202. 'Content-Type': 'application/json;charset=UTF-8'
  203. },
  204. url: mydata_api + '/backstage/addusers',
  205. method: 'POST',
  206. data: data,
  207. dataType: 'json',
  208. success: (res) => {
  209. //100成功
  210. if (res.data.Code == 100) {
  211. console.log("添加用户成功", res);
  212. _self.paging(_self.currentPage);
  213. }
  214. //200失败
  215. else {
  216. console.log('添加用户成功失败200', res);
  217. }
  218. uni.hideLoading();
  219. },
  220. fail: (res) => {
  221. console.log("添加用户成功失败");
  222. uni.hideLoading();
  223. }
  224. });
  225. };
  226. this.$refs.popForm.setContent([
  227. {
  228. 'name':'Ilab账号',
  229. 'input':'',
  230. 'type' :'text'
  231. },
  232. {
  233. 'name':'设置用户',
  234. 'input':mydata_userInfo.userID,
  235. 'type' :'text'
  236. },
  237. {
  238. 'name':'被设置用户ID',
  239. 'input':'',
  240. 'type' :'text'
  241. },
  242. {
  243. 'name':'姓名',
  244. 'input':'',
  245. 'type' :'text'
  246. },
  247. {
  248. 'name':'学校',
  249. 'input':'',
  250. 'type' :'text'
  251. },
  252. {
  253. 'name':'院系',
  254. 'input':'',
  255. 'type' :'text'
  256. },
  257. {
  258. 'name':'专业',
  259. 'input':'',
  260. 'type' :'text'
  261. },
  262. {
  263. 'name':'班级',
  264. 'input':'',
  265. 'type' :'text'
  266. },
  267. {
  268. 'name':'学号',
  269. 'input':'',
  270. 'type' :'text'
  271. },
  272. {
  273. 'name':'Post',
  274. 'input':'',
  275. 'type' :'text'
  276. },
  277. {
  278. 'name':'职务',
  279. 'input':'',
  280. 'type' :'text'
  281. },
  282. {
  283. 'name':'电话',
  284. 'input':'',
  285. 'type' :'text'
  286. },
  287. {
  288. 'name':'邮箱',
  289. 'input':'',
  290. 'type' :'text'
  291. },
  292. {
  293. 'name':'民族',
  294. 'input':'',
  295. 'type' :'text'
  296. },
  297. {
  298. 'name':'政治面貌',
  299. 'input':'',
  300. 'type' :'text'
  301. },
  302. {
  303. 'name':'籍贯',
  304. 'input':'',
  305. 'type' :'text'
  306. },
  307. {
  308. 'name':'证件类型',
  309. 'input':'',
  310. 'type' :'text'
  311. },
  312. {
  313. 'name':'证件号码',
  314. 'input':'',
  315. 'type' :'text'
  316. }
  317. ],callback);
  318. },
  319. modify(dataUser)
  320. {
  321. this.$refs.popForm.isShow(true);
  322. this.$refs.popForm.setTitle('修改用户信息');
  323. let _self = this;
  324. let callback = function(content_arr){
  325. let data = {
  326. "UserID":mydata_userInfo.userID,
  327. "SetUserID" : dataUser.Id,
  328. "Name":content_arr[0].input,
  329. "School":dataUser.School,
  330. "Department":dataUser.Department,
  331. "Profession":dataUser.Profession,
  332. "Class":content_arr[1].input,
  333. "StudentID":Number(content_arr[2].input),
  334. "Post":dataUser.Post,
  335. "PhoneNum":Number(content_arr[3].input),
  336. "Email":dataUser.Email,
  337. "Nation":dataUser.Nation,
  338. "PoliticsStatus":dataUser.PoliticsStatus,
  339. "NativePlace":dataUser.NativePlace,
  340. "Certificate":dataUser.Certificate,
  341. "CertificateNum":dataUser.CertificateNum,
  342. }
  343. // console.log('data=',data)
  344. uni.showLoading({
  345. title: '上传中'
  346. });
  347. uni.request({
  348. header: {
  349. 'Content-Type': 'application/json;charset=UTF-8'
  350. },
  351. url: mydata_api + '/user/setuserinfo',
  352. method: 'POST',
  353. data: data,
  354. dataType: 'json',
  355. success: (res) => {
  356. //100成功
  357. if (res.data.Code == 100) {
  358. console.log("修改用户信息成功", res);
  359. _self.paging(_self.currentPage);
  360. }
  361. //200失败
  362. else {
  363. console.log('修改用户信息失败200', res);
  364. }
  365. uni.hideLoading();
  366. },
  367. fail: (res) => {
  368. console.log("修改用户信息失败");
  369. uni.hideLoading();
  370. }
  371. });
  372. };
  373. this.$refs.popForm.setContent([
  374. {
  375. 'name':'姓名',
  376. 'input':dataUser.Name,
  377. 'type' :'text'
  378. },
  379. {
  380. 'name':'班级',
  381. 'input':dataUser.Class,
  382. 'type' :'text'
  383. },
  384. {
  385. 'name':'学号',
  386. 'input':dataUser.StudentID,
  387. 'type' :'text'
  388. },
  389. {
  390. 'name':'电话',
  391. 'input':dataUser.PhoneNum,
  392. 'type' :'text'
  393. }
  394. ],callback);
  395. },
  396. deleteUser(dataUser)
  397. {
  398. this.$refs.popAlert.isShow(true);
  399. this.$refs.popAlert.setTitle('提示');
  400. let _self = this;
  401. let callback = function(){
  402. let data = {
  403. "UserID":mydata_userInfo.userID,
  404. "DeleteUserID" : dataUser.Id
  405. }
  406. console.log('data=',data)
  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. // 允许文字被选择
  443. th
  444. {
  445. moz-user-select: -moz-text;
  446. -moz-user-select: text;
  447. -o-user-select: text;
  448. -khtml-user-select: text;
  449. -webkit-user-select: text;
  450. -ms-user-select: text;
  451. user-select: text;
  452. }
  453. .m_right {
  454. width: 100%;
  455. margin-top: 5rpx;
  456. padding: 0 150rpx;
  457. background-color: #fff;
  458. box-shadow: 3px 0px 6px 0px rgba(0, 0, 0, 0.1);
  459. .m_right_hander {
  460. text-align: right;
  461. height: 250rpx;
  462. position: relative;
  463. .m_btn_red {
  464. position: absolute;
  465. height: 80rpx;
  466. line-height: 80rpx;
  467. padding: 0 40rpx;
  468. right: 0;
  469. top: 50%;
  470. transform: translateY(-50%);
  471. background: #EA252C;
  472. color: #fff;
  473. }
  474. }
  475. }
  476. tbody tr {
  477. // border-top: 2rpx solid #DDDDDD !important;
  478. border: 2rpx solid #DDDDDD !important;
  479. }
  480. th {
  481. border: 2rpx solid #DDDDDD !important;
  482. }
  483. tbody tr th {
  484. font-weight: 400 !important;
  485. height: 140rpx;
  486. line-height: 140rpx;
  487. border: 2rpx solid #DDDDDD !important;
  488. }
  489. // tbody tr:hover {
  490. // // color: #fff;
  491. // background: #FDEBEC;
  492. // // opacity: 0.08;
  493. // }
  494. .center{
  495. display: flex;
  496. justify-content: center;
  497. align-items: center;
  498. }
  499. .m-table-hander {
  500. background-color: #FFF8F7;
  501. height: 140rpx;
  502. line-height: 140rpx;
  503. font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
  504. font-weight: bold;
  505. }
  506. .btn_bg{
  507. // border: 1rpx solid #DDDDDD;
  508. // display: flex;
  509. // justify-content: center;
  510. // align-items: center;
  511. }
  512. .m_edit {
  513. // position: relative;
  514. // top: 50%;
  515. // left: 50%;
  516. // transform: translate(-50%, -50%);
  517. background: rgb(67, 127, 250);
  518. color: rgb(255, 255, 255);
  519. // width: 60%;
  520. }
  521. .m_delete {
  522. background: rgb(234, 37, 44);
  523. color: rgb(255, 255, 255);
  524. // width: 60%;
  525. }
  526. .m_right_footer {
  527. margin-top: 80rpx;
  528. }
  529. .m_paging {
  530. text-align: right;
  531. .m_paging_item {
  532. padding: 10rpx 18rpx;
  533. border: 1rpx solid #DDDDDD;
  534. border-radius: 8rpx;
  535. margin-right: 10rpx;
  536. }
  537. .p_act {
  538. background: #EA252C;
  539. color: #fff;
  540. border: inherit;
  541. }
  542. }
  543. .m_paging_item:hover {
  544. background: #EA252C;
  545. color: #fff;
  546. border: inherit;
  547. }
  548. .m_act1 {
  549. color: #FF0019;
  550. }
  551. </style>