set_picture.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="container">
  3. <view class="headPortrait flex">
  4. <view class="pictures">
  5. <image src="../../static/img/myimg/YongHu@3x.png" v-bind:class="pictures" @click="oKSelected(1)">
  6. </image>
  7. <view style="margin: 0 auto;text-align: center;margin-top: -15px;" v-if="pictures == 'picture1'">
  8. <image src="../../static/img/login/select@3x.png" class="duihao"></image>
  9. </view>
  10. <view class="title">默认</view>
  11. </view>
  12. <view class="pictures">
  13. <image src="../../static/img/myimg/SiJi@3x.png" v-bind:class="picturesTwo" @click="oKSelected(2)">
  14. </image>
  15. <view style="margin: 0 auto;text-align: center;margin-top: -15px;" v-if="picturesTwo == 'picture1'">
  16. <image src="../../static/img/login/select@3x.png" class="duihao"></image>
  17. </view>
  18. <view class="title">司机</view>
  19. </view>
  20. <view class="pictures">
  21. <image src="../../static/img/myimg/LiangShang@3x.png" v-bind:class="picturesThree"
  22. @click="oKSelected(3)"></image>
  23. <view style="margin: 0 auto;text-align: center;margin-top: -15px;" v-if="picturesThree == 'picture1'">
  24. <image src="../../static/img/login/select@3x.png" class="duihao"></image>
  25. </view>
  26. <view class="title">粮商</view>
  27. </view>
  28. <view class="pictures">
  29. <image src="../../static/img/myimg/LiangNong@3x.png" v-bind:class="picturesFour" @click="oKSelected(4)">
  30. </image>
  31. <view style="margin: 0 auto;text-align: center;margin-top: -15px;" v-if="picturesFour == 'picture1'">
  32. <image src="../../static/img/login/select@3x.png" class="duihao"></image>
  33. </view>
  34. <view class="title">粮农</view>
  35. </view>
  36. </view>
  37. <view class="btn" @click="commit">
  38. 保存
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import {
  44. mapState
  45. } from 'vuex';
  46. export default {
  47. data() {
  48. return {
  49. pictures: "picture",
  50. picturesTwo: "picture",
  51. picturesThree: "picture",
  52. picturesFour: "picture",
  53. identityUrl: "",
  54. deptListurl: {},
  55. }
  56. },
  57. computed: {
  58. ...mapState(['hasLogin', 'userInfo'])
  59. },
  60. methods: {
  61. oKSelected(number) {
  62. if (number == 1) {
  63. if (this.pictures == "picture") {
  64. this.pictures = "picture1"
  65. this.picturesTwo = "picture"
  66. this.picturesThree = "picture"
  67. this.picturesFour = "picture"
  68. this.identityUrl = "https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/162874144867649.png"
  69. } else {
  70. this.pictures = "picture"
  71. }
  72. } else if (number == 2) {
  73. if (this.picturesTwo == "picture") {
  74. this.picturesTwo = "picture1"
  75. this.pictures = "picture"
  76. this.picturesThree = "picture"
  77. this.picturesFour = "picture"
  78. this.identityUrl = "https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/162874149682940.png "
  79. } else {
  80. this.picturesTwo = "picture"
  81. this.identityUrl = ""
  82. }
  83. } else if (number == 3) {
  84. if (this.picturesThree == "picture") {
  85. this.picturesThree = "picture1"
  86. this.pictures = "picture"
  87. this.picturesTwo = "picture"
  88. this.picturesFour = "picture"
  89. this.identityUrl = "https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/1628741540162138.png"
  90. } else {
  91. this.picturesThree = "picture"
  92. this.identityUrl = ""
  93. }
  94. } else if (number == 4) {
  95. if (this.picturesFour == "picture") {
  96. this.picturesFour = "picture1"
  97. this.pictures = "picture"
  98. this.picturesTwo = "picture"
  99. this.picturesThree = "picture"
  100. this.identityUrl = "https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/162874156836497.png"
  101. } else {
  102. this.picturesFour = "picture"
  103. this.identityUrl = ""
  104. }
  105. }
  106. },
  107. commit() {
  108. if (this.identityUrl == null || this.identityUrl == "") {
  109. this.$api.msg('请选择一张图片!')
  110. return
  111. }
  112. var that = this
  113. that.deptListurl.avatarUrl = that.identityUrl
  114. that.deptListurl.id = that.userInfo.id
  115. that.$api.doRequest('post', '/commonUser/editUserInfo', that.deptListurl).then(
  116. res => {
  117. if (res.data.code == 200) {
  118. uni.showToast({
  119. title: '修改成功!',
  120. icon: 'success',
  121. duration: 2000,
  122. success() {
  123. setTimeout(()=>{
  124. that.userInfo.avatarUrl = that.identityUrl
  125. var _student = uni.getStorageSync('userInfo');
  126. _student.avatarUrl = that.identityUrl;
  127. uni.setStorageSync('userInfo', _student);
  128. var name = 'userInfo';
  129. var value = _student;
  130. that.$store.commit('$uStore', {
  131. name,
  132. value
  133. });
  134. // this.$api.msg('修改成功2!')
  135. uni.navigateBack({
  136. delta:1
  137. })
  138. },2000)
  139. }
  140. })
  141. }
  142. })
  143. .catch(res => {
  144. if(res.data.errmsg){
  145. uni.showToast({
  146. title: res.data.errmsg,
  147. icon: 'none',
  148. duration: 2000
  149. })
  150. }
  151. else{
  152. uni.showToast({
  153. title: "系统异常,请联系管理员",
  154. icon: 'none',
  155. duration: 2000
  156. })
  157. }
  158. });
  159. },
  160. }
  161. }
  162. </script>
  163. <style>
  164. .container {
  165. padding: 10px 10px 0px;
  166. background-color: #F5F6FA;
  167. }
  168. .headPortrait {
  169. width: 100%;
  170. background-color: #FFFFFF;
  171. border-radius: 20px;
  172. }
  173. .picture {
  174. width: 70px;
  175. height: 70px;
  176. margin: 0 auto;
  177. margin-top: 10px;
  178. }
  179. .picture1 {
  180. width: 70px;
  181. height: 70px;
  182. margin: 0 auto;
  183. border-radius: 35px;
  184. margin-top: 10px;
  185. border: 2px solid #22C572;
  186. }
  187. .title {
  188. text-align: center;
  189. margin: 16px 0;
  190. font-size: 14px;
  191. font-weight: 500;
  192. }
  193. .pictures {
  194. margin-left: 15px;
  195. }
  196. .duihao {
  197. width: 18px;
  198. height: 18px;
  199. text-align: center;
  200. margin: 0 auto;
  201. }
  202. .btn {
  203. width: 100%;
  204. height: 50px;
  205. background-color: #FFFFFF;
  206. text-align: center;
  207. color: #22C572;
  208. font-size: 20px;
  209. margin-top: 16px;
  210. border-radius: 20px;
  211. line-height: 50px;
  212. font-weight: 500;
  213. }
  214. </style>