set_picture.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. uni.showModal({
  114. content: "您确定要更改图像?",
  115. showCancel: true,
  116. confirmText: '确定',
  117. success: function(res) {
  118. if (res.confirm) {
  119. that.deptListurl.avatarUrl = that.identityUrl
  120. that.$api.doRequest('post', '/commonUser/editUserInfo', that.deptListurl).then(
  121. res => {
  122. if (res.data.code == 200) {
  123. that.userInfo.avatarUrl = that.identityUrl
  124. var _student = wx.getStorageSync('userInfo');
  125. _student.avatarUrl = that.identityUrl;
  126. wx.setStorageSync('userInfo', _student);
  127. uni.navigateTo({
  128. url: `/pages/user/setUp`
  129. })
  130. }
  131. })
  132. .catch(res => {
  133. uni.showToast({
  134. title: res.errmsg,
  135. icon: 'none',
  136. duration: 2000
  137. })
  138. });
  139. } else if (res.cancel) {
  140. // console.log('用户点击取消');
  141. }
  142. },
  143. })
  144. },
  145. }
  146. }
  147. </script>
  148. <style>
  149. .container {
  150. padding: 10px 10px 0px;
  151. background-color: #F5F6FA;
  152. }
  153. .headPortrait {
  154. width: 100%;
  155. background-color: #FFFFFF;
  156. border-radius: 20px;
  157. }
  158. .picture {
  159. width: 70px;
  160. height: 70px;
  161. margin: 0 auto;
  162. margin-top: 10px;
  163. }
  164. .picture1 {
  165. width: 70px;
  166. height: 70px;
  167. margin: 0 auto;
  168. border-radius: 35px;
  169. margin-top: 10px;
  170. border: 2px solid #22C572;
  171. }
  172. .title {
  173. text-align: center;
  174. margin: 16px 0;
  175. font-size: 14px;
  176. font-weight: 500;
  177. }
  178. .pictures {
  179. margin-left: 15px;
  180. }
  181. .duihao {
  182. width: 18px;
  183. height: 18px;
  184. text-align: center;
  185. margin: 0 auto;
  186. }
  187. .btn {
  188. width: 100%;
  189. height: 50px;
  190. background-color: #FFFFFF;
  191. text-align: center;
  192. color: #22C572;
  193. font-size: 20px;
  194. margin-top: 16px;
  195. border-radius: 20px;
  196. line-height: 50px;
  197. font-weight: 500;
  198. }
  199. </style>