schoolidCard.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div class="card" style="margin-bottom: 20px">
  3. <van-row>
  4. <van-col span="14">
  5. <h3><strong>个人资料</strong></h3>
  6. </van-col>
  7. <van-col span="6" style="">
  8. <p style="border-bottom: solid 1px #e4e4e4" @click="toggleReadOnly()">{{isReadonly ? "编辑" : "保存"}}</p>
  9. </van-col>
  10. </van-row>
  11. <p>昵称</p>
  12. <van-cell-group>
  13. <van-field
  14. placeholder=" "
  15. v-model="personName"
  16. :error="personError"
  17. @click="personError=false"
  18. required
  19. maxlength="10"
  20. :readonly="isReadonly"
  21. />
  22. </van-cell-group>
  23. <p>性别</p>
  24. <van-radio-group v-model="gender">
  25. <van-radio name="0" checked-color="#fd6740" style="float: left; margin-right: 20px" :disabled="isReadonly"
  26. >男</van-radio>
  27. <van-radio name="1" checked-color="#fd6740" :disabled="isReadonly"
  28. >女</van-radio>
  29. </van-radio-group>
  30. <p>微信号</p>
  31. <van-cell-group>
  32. <van-field
  33. placeholder=" "
  34. v-model="weixinName"
  35. :error="weixinError"
  36. @click="weixinError=false"
  37. required
  38. maxlength="20"
  39. :readonly="isReadonly"
  40. />
  41. </van-cell-group>
  42. <p>宿舍区</p>
  43. <van-radio-group v-model="dormDistrict">
  44. <van-radio name="0" checked-color="#fd6740" style="float: left; margin-right: 20px" :disabled="isReadonly">南区</van-radio>
  45. <van-radio name="1" checked-color="#fd6740" style="float: left; margin-right: 20px" :disabled="isReadonly">西南</van-radio>
  46. <van-radio name="2" checked-color="#fd6740" style="float: left; margin-right: 20px" :disabled="isReadonly">斋区</van-radio>
  47. <van-radio name="3" checked-color="#fd6740" style="float: left; margin-right: 20px" :disabled="isReadonly">桂庙</van-radio>
  48. <van-radio name="4" checked-color="#fd6740" :disabled="isReadonly">西丽</van-radio>
  49. </van-radio-group>
  50. </div>
  51. </template>
  52. <script>
  53. import { Row, Col,
  54. CellGroup, Field,
  55. RadioGroup, Radio,
  56. } from 'vant';
  57. import {BasicFunction} from "../connector/basic-service";
  58. export default {
  59. name: "schoolidCard",
  60. components: {
  61. [CellGroup.name]: CellGroup, [Field.name]: Field,
  62. [RadioGroup.name]: RadioGroup, [Radio.name]: Radio,
  63. [Row.name]: Row, [Col.name]: Col,
  64. },
  65. data() {
  66. return {
  67. gender: '0',
  68. dormDistrict: '1',
  69. personName: '',
  70. personError: false,
  71. weixinName: '',
  72. weixinError: false,
  73. isReadonly: true,
  74. userDo: {},
  75. reviewDo: {},
  76. }
  77. },
  78. methods: {
  79. uploadNameChange: function () {
  80. BasicFunction.get_data("smartUsers/updateBatch", function (response) {
  81. console.log("------ Data Rcvd in PresentReg --------");
  82. console.log(response);
  83. if (response.ret === "10000") {
  84. history.go(0);
  85. } else {
  86. // 注册失败的处理
  87. Toast.fail("上传失败,请检查网络");
  88. }
  89. }, [this.userDo]);
  90. },
  91. uploadReviewChange: function () {
  92. BasicFunction.get_data("smartIdentity/updateBatch", function (response) {
  93. console.log("------ Data Rcvd in PresentReg --------");
  94. console.log(response);
  95. if (response.ret === "10000") {
  96. history.go(0);
  97. } else {
  98. // 注册失败的处理
  99. Toast.fail("上传失败,请检查网络");
  100. }
  101. }, [this.reviewDo]);
  102. },
  103. toggleReadOnly: function () {
  104. if (!this.isReadonly){
  105. this.savePage()
  106. }
  107. this.isReadonly = !this.isReadonly;
  108. },
  109. savePage() {
  110. // 检验输入
  111. // var userId = localStorage.getItem(....
  112. if (this.personName.length === 0) {
  113. this.personError = true;
  114. return;
  115. } else if (this.weixinName.length >= 20) {
  116. this.weixinError = true;
  117. Toast.fail('最多输入20个字符');
  118. return;
  119. }
  120. // post_present()
  121. this.userDo.name = this.weixinName;
  122. this.uploadNameChange();
  123. this.reviewDo.gender = this.gender;
  124. this.reviewDo.dormDistrict = this.dormDistrict;
  125. this.uploadReviewChange();
  126. },
  127. getIdentityInfo: function (obj) {
  128. //this;
  129. var userId = localStorage.getItem("frontend-userid");
  130. window.schoolIdCard = this;
  131. BasicFunction.get_data("smartUsers/list?uid=" + userId, function (response) {
  132. console.log("------ Data Rcvd in PresentReg --------");
  133. console.log(response);
  134. if (response.ret === "10000") {
  135. var t = response.model.list;
  136. window.schoolIdCard.personName = t[0].name; // 左侧是vue页面内的变量名字, 右侧是后台数据里的变量名称
  137. window.schoolIdCard.userDo = t[0];
  138. } else {
  139. // 注册失败的处理
  140. Toast.fail("获取失败,请检查网络");
  141. }
  142. }, [{}]);
  143. },
  144. getReviewInfo:function (obj) {
  145. var userId = localStorage.getItem("frontend-userid");
  146. window.schoolIdCard = this;
  147. BasicFunction.get_data("smartIdentity/list?userId=" + userId, function (response) {
  148. console.log("------ Data Rcvd in PresentReg --------");
  149. console.log(response);
  150. if (response.ret === "10000") {
  151. var t = response.model.list;
  152. window.schoolIdCard.gender = t[0].userSex; // 左侧是vue页面内的变量名字, 右侧是后台数据里的变量名称
  153. window.schoolIdCard.dormDistrict = t[0].dormDistrict;
  154. window.schoolIdCard.reviewDo = t[0];
  155. } else {
  156. Toast.fail("获取失败,请检查网络");
  157. }
  158. }, [{}]);
  159. }
  160. },
  161. created: function () {
  162. window.schoolIdCard = this;
  163. this.getIdentityInfo(window.schoolIdCard);
  164. this.getReviewInfo(window.schoolIdCard);
  165. }
  166. }
  167. </script>
  168. <style scoped>
  169. p, h3 {
  170. color: #fd6740;
  171. }
  172. h3 {
  173. padding: 5px;
  174. border-bottom: solid 1px #e4e4e4;
  175. }
  176. p {
  177. padding-top: 3px;
  178. }
  179. .card {
  180. background-color: white;
  181. margin: 20px 20px;
  182. border: solid 1px #e4e4e4;
  183. padding: 15px;
  184. text-align: left;
  185. }
  186. </style>