user.vue 15 KB

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