set_picture.vue 6.3 KB

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