set_picture.vue 5.7 KB

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