schoolidCard.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <div class="card" >
  3. <van-row style="border-bottom: solid 1px #e4e4e4;">
  4. <van-col span="14">
  5. <h3><strong>个人资料</strong></h3>
  6. </van-col>
  7. <van-col span="6" >
  8. <p @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="1" checked-color="#fd6740" style="float: left; margin-right: 20px" :disabled="isReadonly">男</van-radio>
  26. <van-radio name="2" checked-color="#fd6740" :disabled="isReadonly">女</van-radio>
  27. </van-radio-group>
  28. <p>微信号</p>
  29. <van-cell-group>
  30. <van-field
  31. placeholder=" "
  32. v-model="weixinName"
  33. :error="weixinError"
  34. @click="weixinError=false"
  35. required
  36. maxlength="20"
  37. :readonly="isReadonly"
  38. />
  39. </van-cell-group>
  40. <p>宿舍区</p>
  41. <van-radio-group v-model="dormDistrict">
  42. <van-radio name="0" checked-color="#fd6740" style="float: left; margin: 0 0 15px 10px"
  43. :disabled="isReadonly">斋区
  44. </van-radio>
  45. <van-radio name="1" checked-color="#fd6740" style="float: left; margin: 0 10px 15px 10px"
  46. :disabled="isReadonly">西南
  47. </van-radio>
  48. <van-radio name="2" checked-color="#fd6740" style="margin: 0 10px 15px 10px" :disabled="isReadonly">南区
  49. </van-radio>
  50. <van-radio name="3" checked-color="#fd6740" style="float: left; margin: 0 0 15px 10px"
  51. :disabled="isReadonly">桂庙
  52. </van-radio>
  53. <van-radio name="4" checked-color="#fd6740" style="float: left; margin: 0 10px 15px"
  54. :disabled="isReadonly">西丽
  55. </van-radio>
  56. </van-radio-group>
  57. </div>
  58. </template>
  59. <script>
  60. import { Row, Col,
  61. CellGroup, Field,
  62. RadioGroup, Radio,
  63. Toast
  64. } from 'vant';
  65. import {BasicFunction} from "../connector/basic-service";
  66. export default {
  67. name: "schoolidCard",
  68. components: {
  69. [CellGroup.name]: CellGroup, [Field.name]: Field,
  70. [RadioGroup.name]: RadioGroup, [Radio.name]: Radio,
  71. [Row.name]: Row, [Col.name]: Col,
  72. },
  73. data() {
  74. return {
  75. gender: '0',
  76. dormDistrict: '1',
  77. personName: '',
  78. personError: false,
  79. weixinName: '',
  80. weixinError: false,
  81. isReadonly: true,
  82. userDo: {},
  83. reviewDo: {},
  84. }
  85. },
  86. methods: {
  87. uploadNameChange: function () {
  88. let that = this;
  89. BasicFunction.get_data("smartUsers/updateBatch", function (response) {
  90. // console.log("------ Data Rcvd in uploadNameChange --------");
  91. // console.log(response);
  92. if (response.ret === "10000") {
  93. that.isReadonly = true;
  94. Toast.success("上传成功")
  95. } else {
  96. Toast.fail("上传失败,请检查网络");
  97. }
  98. }, [this.userDo]);
  99. },
  100. uploadReviewChange: function () {
  101. let that = this;
  102. BasicFunction.get_data("smartIdentity/updateBatch", function (response) {
  103. // console.log("------ Data Rcvd in uploadReviewChange --------");
  104. // console.log(response);
  105. if (response.ret === "10000") {
  106. //history.go(0);
  107. that.isReadonly = true;
  108. Toast.success("上传成功")
  109. } else {
  110. Toast.fail("上传失败,请检查网络");
  111. }
  112. }, [this.reviewDo]);
  113. },
  114. toggleReadOnly: function () {
  115. if (!this.isReadonly){
  116. this.savePage()
  117. }
  118. this.isReadonly = !this.isReadonly;
  119. },
  120. savePage() {
  121. // 检验输入
  122. // var userId = localStorage.getItem(....
  123. if (this.personName.length === 0) {
  124. this.personError = true;
  125. return;
  126. } else if (this.weixinName.length < 6) {
  127. this.weixinError = true;
  128. Toast.fail('请输入正确格式的微信号');
  129. return;
  130. }
  131. // post_present()
  132. this.userDo.name = this.personName; // changed to personName instead.
  133. this.uploadNameChange();
  134. this.reviewDo.userSex = parseInt(this.gender); // TODO: 请注意 int <-> string 转换
  135. this.reviewDo.dormDistrict = parseInt(this.dormDistrict);
  136. this.uploadReviewChange();
  137. },
  138. getIdentityInfo: function (obj) {
  139. //this;
  140. if (!localStorage.getItem('frontend-userid')) {
  141. this.$router.push('login');
  142. return;
  143. }
  144. let userId = localStorage.getItem("frontend-userid");
  145. let that = this;
  146. BasicFunction.get_data("smartUsers/list?uid=" + userId, function (response) {
  147. // console.log("------ Data Rcvd in getIdentityInfo --------");
  148. // console.log(response);
  149. if (response === undefined || response.model === undefined || response.model.list === undefined || response.model.list.length === 0) {
  150. that.$router.push('login');
  151. }
  152. try {
  153. let t = response.model.list;
  154. if (response.ret === "10000") {
  155. that.personName = t[0].name; // 左侧是vue页面内的变量名字, 右侧是后台数据里的变量名称
  156. that.userDo = t[0];
  157. } else Toast.fail("获取信息失败,请检查网络");
  158. } catch (e) {
  159. console.warn(e);
  160. Toast.fail("获取信息失败,请检查网络");
  161. }
  162. }, [{}]);
  163. },
  164. getReviewInfo:function (obj) {
  165. if (!localStorage.getItem('frontend-userid')) {
  166. this.$router.push('login');
  167. return;
  168. }
  169. let userId = localStorage.getItem("frontend-userid");
  170. let that = this;
  171. BasicFunction.get_data("smartIdentity/list?userId=" + userId, function (response) {
  172. // console.log("------ Data Rcvd in getReviewInfo --------");
  173. // console.log(response);
  174. if (response == undefined || response.model == undefined || response.model.list == undefined || response.model.list.length == 0) {
  175. that.$router.push('login');
  176. return;
  177. }
  178. try {
  179. let t = response.model.list;
  180. if (response.ret === "10000" && t[0] != undefined && t[0].userSex != undefined) {
  181. that.gender = "" + t[0].userSex; // 左侧是vue页面内的变量名字, 右侧是后台数据里的变量名称
  182. that.dormDistrict = t[0].dormDistrict.toString(); //TODO: 请注意文本数字转换
  183. that.reviewDo = t[0];
  184. that.weixinName = t[0].userWxAccount;
  185. } else Toast.fail("获取失败,请检查网络");
  186. } catch (e) {
  187. console.warn(e);
  188. Toast.fail("获取失败,请检查网络");
  189. }
  190. }, [{}]);
  191. }
  192. },
  193. created: function () {
  194. if (!localStorage.getItem('frontend-userid')) {
  195. this.$router.push('login');
  196. return;
  197. }
  198. let that = this;
  199. this.getIdentityInfo(that);
  200. this.getReviewInfo(that);
  201. }
  202. }
  203. </script>
  204. <style scoped>
  205. p, h3 {
  206. color: #fd6740;
  207. }
  208. h3 {
  209. padding: 3px;
  210. }
  211. p {
  212. padding-top: 7px;
  213. }
  214. .card {
  215. background-color: white;
  216. margin-top: 20px;
  217. margin-left: 20px;
  218. margin-right: 20px;
  219. margin-bottom: 20px;
  220. border: solid 1px #e4e4e4;
  221. padding-top: 15px;
  222. padding-left: 15px;
  223. padding-right: 15px;
  224. padding-bottom: 40px;
  225. text-align: left;
  226. }
  227. </style>