set_picture.vue 6.2 KB

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