user.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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">上一页</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">下一页</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.setTotalScore();
  100. this.currentPage = i;
  101. uni.hideLoading();
  102. this.showNextOrLastPageBtn();
  103. }
  104. //200失败
  105. else {
  106. console.log('suc200', res);
  107. uni.hideLoading();
  108. }
  109. },
  110. fail: (res) => {
  111. console.log("请求失败****");
  112. uni.hideLoading();
  113. }
  114. });
  115. },
  116. initPage() {
  117. this.paging(1);
  118. },
  119. //分数合并
  120. setTotalScore() {
  121. for (let i = 0; i < this.dataUsers_all.length; i++) {
  122. let totalScore = 0;
  123. for (let j = 0; j < this.dataUsers_all[i].UserScore.length; j++) {
  124. let ascore = Number(this.dataUsers_all[i].UserScore[j]);
  125. if (ascore) {
  126. totalScore += ascore;
  127. }
  128. }
  129. this.dataUsers_all[i].TotalScore = totalScore;
  130. }
  131. },
  132. showNextOrLastPageBtn()
  133. {
  134. if((this.pageTotalNum-this.totalItem)>0)
  135. {
  136. this.bShowLastPageBtn = false;
  137. this.bShowNextPageBtn = false;
  138. // console.log('0000')
  139. }
  140. else if(this.pageTotalNum==this.currentPage)
  141. {
  142. this.bShowLastPageBtn = true;
  143. this.bShowNextPageBtn = false;
  144. // console.log('11111')
  145. }
  146. else if(1==this.currentPage)
  147. {
  148. this.bShowLastPageBtn = false;
  149. this.bShowNextPageBtn = true;
  150. // console.log('2222')
  151. }
  152. else
  153. {
  154. this.bShowLastPageBtn = true;
  155. this.bShowNextPageBtn = true;
  156. // console.log('333333')
  157. }
  158. },
  159. addUser(){
  160. this.$refs.popForm.isShow(true);
  161. this.$refs.popForm.setTitle('添加用户');
  162. let _self = this;
  163. let callback = function(content_arr){
  164. let data = {
  165. "IlabAccount":content_arr[0].input,
  166. "UserID" : content_arr[1].input,
  167. "SetUserID":content_arr[2].input,
  168. "Name":content_arr[3].input,
  169. "School":content_arr[4].input,
  170. "Department":content_arr[5].input,
  171. "Profession":content_arr[6].input,
  172. "Class":content_arr[7].input,
  173. "StudentID":content_arr[8].input,
  174. "Post":content_arr[9].input,
  175. "PhoneNum":content_arr[10].input,
  176. "Email":content_arr[11].input,
  177. "Nation":content_arr[12].input,
  178. "PoliticsStatus":content_arr[13].input,
  179. "NativePlace":content_arr[14].input,
  180. "Certificate":content_arr[15].input,
  181. "CertificateNum":content_arr[16].input,
  182. }
  183. // console.log('data===',data)
  184. uni.showLoading({
  185. title: '上传中'
  186. });
  187. uni.request({
  188. header: {
  189. 'Content-Type': 'application/json;charset=UTF-8'
  190. },
  191. url: mydata_api + '/backstage/addusers',
  192. method: 'POST',
  193. data: data,
  194. dataType: 'json',
  195. success: (res) => {
  196. //100成功
  197. if (res.data.Code == 100) {
  198. console.log("添加用户成功", res);
  199. _self.paging(_self.currentPage);
  200. }
  201. //200失败
  202. else {
  203. console.log('添加用户成功失败200', res);
  204. }
  205. uni.hideLoading();
  206. },
  207. fail: (res) => {
  208. console.log("添加用户成功失败");
  209. uni.hideLoading();
  210. }
  211. });
  212. };
  213. this.$refs.popForm.setContent([
  214. {
  215. 'name':'Ilab账号',
  216. 'input':'',
  217. 'type' :'text'
  218. },
  219. {
  220. 'name':'设置用户',
  221. 'input':mydata_userInfo.userID,
  222. 'type' :'text'
  223. },
  224. {
  225. 'name':'被设置用户ID',
  226. 'input':'',
  227. 'type' :'text'
  228. },
  229. {
  230. 'name':'姓名',
  231. 'input':'',
  232. 'type' :'text'
  233. },
  234. {
  235. 'name':'学校',
  236. 'input':'',
  237. 'type' :'text'
  238. },
  239. {
  240. 'name':'院系',
  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':'Post',
  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':'邮箱',
  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. ],callback);
  305. },
  306. modify(dataUser)
  307. {
  308. this.$refs.popForm.isShow(true);
  309. this.$refs.popForm.setTitle('修改用户信息');
  310. let _self = this;
  311. let callback = function(content_arr){
  312. let data = {
  313. "UserID":mydata_userInfo.userID,
  314. "SetUserID" : dataUser.Id,
  315. "Name":content_arr[0].input,
  316. "School":dataUser.School,
  317. "Department":dataUser.Department,
  318. "Profession":dataUser.Profession,
  319. "Class":content_arr[1].input,
  320. "StudentID":content_arr[2].input,
  321. "Post":dataUser.Post,
  322. "PhoneNum":content_arr[3].input,
  323. "Email":dataUser.Email,
  324. "Nation":dataUser.Nation,
  325. "PoliticsStatus":dataUser.PoliticsStatus,
  326. "NativePlace":dataUser.NativePlace,
  327. "Certificate":dataUser.Certificate,
  328. "CertificateNum":dataUser.CertificateNum,
  329. }
  330. uni.showLoading({
  331. title: '上传中'
  332. });
  333. uni.request({
  334. header: {
  335. 'Content-Type': 'application/json;charset=UTF-8'
  336. },
  337. url: mydata_api + '/user/setuserinfo',
  338. method: 'POST',
  339. data: data,
  340. dataType: 'json',
  341. success: (res) => {
  342. //100成功
  343. if (res.data.Code == 100) {
  344. console.log("修改用户信息成功", res);
  345. _self.paging(_self.currentPage);
  346. }
  347. //200失败
  348. else {
  349. console.log('修改用户信息失败200', res);
  350. }
  351. uni.hideLoading();
  352. },
  353. fail: (res) => {
  354. console.log("修改用户信息失败");
  355. uni.hideLoading();
  356. }
  357. });
  358. };
  359. this.$refs.popForm.setContent([
  360. {
  361. 'name':'姓名',
  362. 'input':dataUser.Name,
  363. 'type' :'text'
  364. },
  365. {
  366. 'name':'班级',
  367. 'input':dataUser.Class,
  368. 'type' :'text'
  369. },
  370. {
  371. 'name':'学号',
  372. 'input':dataUser.StudentID,
  373. 'type' :'text'
  374. },
  375. {
  376. 'name':'电话',
  377. 'input':dataUser.PhoneNum,
  378. 'type' :'text'
  379. }
  380. ],callback);
  381. },
  382. deleteUser(dataUser)
  383. {
  384. this.$refs.popAlert.isShow(true);
  385. this.$refs.popAlert.setTitle('提示');
  386. let _self = this;
  387. let callback = function(){
  388. let data = {
  389. "UserID":mydata_userInfo.userID,
  390. "DeleteUserID" : dataUser.Id
  391. }
  392. uni.showLoading({
  393. title: '上传中'
  394. });
  395. uni.request({
  396. header: {
  397. 'Content-Type': 'application/json;charset=UTF-8'
  398. },
  399. url: mydata_api + '/backstage/deleteuser',
  400. method: 'POST',
  401. data: data,
  402. dataType: 'json',
  403. success: (res) => {
  404. //100成功
  405. if (res.data.Code == 100) {
  406. console.log("删除用户成功", res);
  407. _self.paging(_self.currentPage);
  408. }
  409. //200失败
  410. else {
  411. console.log('删除用户失败200', res);
  412. }
  413. uni.hideLoading();
  414. },
  415. fail: (res) => {
  416. console.log("删除用户失败");
  417. uni.hideLoading();
  418. }
  419. });
  420. }
  421. this.$refs.popAlert.setContent('是否删除用户',callback);
  422. },
  423. }
  424. }
  425. </script>
  426. <style lang="scss">
  427. .m_right {
  428. width: 100%;
  429. margin-top: 5rpx;
  430. padding: 0 150rpx;
  431. background-color: #fff;
  432. box-shadow: 3px 0px 6px 0px rgba(0, 0, 0, 0.1);
  433. .m_right_hander {
  434. text-align: right;
  435. height: 250rpx;
  436. position: relative;
  437. .m_btn_red {
  438. position: absolute;
  439. height: 80rpx;
  440. line-height: 80rpx;
  441. padding: 0 40rpx;
  442. right: 0;
  443. top: 50%;
  444. transform: translateY(-50%);
  445. background: #EA252C;
  446. color: #fff;
  447. }
  448. }
  449. }
  450. tbody tr {
  451. // border-top: 2rpx solid #DDDDDD !important;
  452. border: 2rpx solid #DDDDDD !important;
  453. }
  454. th {
  455. border: 2rpx solid #DDDDDD !important;
  456. }
  457. tbody tr th {
  458. font-weight: 400 !important;
  459. height: 140rpx;
  460. line-height: 140rpx;
  461. border: 2rpx solid #DDDDDD !important;
  462. }
  463. // tbody tr:hover {
  464. // // color: #fff;
  465. // background: #FDEBEC;
  466. // // opacity: 0.08;
  467. // }
  468. .center{
  469. display: flex;
  470. justify-content: center;
  471. align-items: center;
  472. }
  473. .m-table-hander {
  474. background-color: #FFF8F7;
  475. height: 140rpx;
  476. line-height: 140rpx;
  477. font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
  478. font-weight: bold;
  479. }
  480. .btn_bg{
  481. // border: 1rpx solid #DDDDDD;
  482. // display: flex;
  483. // justify-content: center;
  484. // align-items: center;
  485. }
  486. .m_edit {
  487. // position: relative;
  488. // top: 50%;
  489. // left: 50%;
  490. // transform: translate(-50%, -50%);
  491. background: rgb(67, 127, 250);
  492. color: rgb(255, 255, 255);
  493. // width: 60%;
  494. }
  495. .m_delete {
  496. background: rgb(234, 37, 44);
  497. color: rgb(255, 255, 255);
  498. // width: 60%;
  499. }
  500. .m_right_footer {
  501. margin-top: 80rpx;
  502. }
  503. .m_paging {
  504. text-align: right;
  505. .m_paging_item {
  506. padding: 10rpx 18rpx;
  507. border: 1rpx solid #DDDDDD;
  508. border-radius: 8rpx;
  509. margin-right: 10rpx;
  510. }
  511. .p_act {
  512. background: #EA252C;
  513. color: #fff;
  514. border: inherit;
  515. }
  516. }
  517. .m_paging_item:hover {
  518. background: #EA252C;
  519. color: #fff;
  520. border: inherit;
  521. }
  522. .m_act1 {
  523. color: #FF0019;
  524. }
  525. </style>