set_picture.vue 5.7 KB

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