set_picture.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <view class="container">
  3. <view class="headPortrait">
  4. <view style="text-align: center;" v-if="!src">
  5. <view class="plus" v-if="!src">
  6. <u-icon name="plus" color="#afb3bf" size="50" ></u-icon>
  7. </view>
  8. <image :src="src" class="avatar" @tap="upload"></image>
  9. <view class="item" @tap="upload">自定义</view>
  10. </view>
  11. <view style="text-align: center;padding-top: 70rpx;border-radius: 50%;" v-else>
  12. <image :src="src" class="avatar1" @tap="upload"></image>
  13. <view class="item" @tap="upload">自定义</view>
  14. </view>
  15. </view>
  16. <view class="headPortrait flex">
  17. <view class="pictures">
  18. <image src="../../static/img/myimg/YongHu@3x.png" v-bind:class="pictures" @click="oKSelected(1)">
  19. </image>
  20. <view style="margin: 0 auto;text-align: center;margin-top: -15px;" v-if="pictures == 'picture1'">
  21. <image src="../../static/img/login/duihao2@3x.png" class="duihao"></image>
  22. </view>
  23. <view v-else style='margin: 0 auto;text-align: center;margin-top: -15px;width:18px;height:21px;'></view>
  24. <view class="title">默认</view>
  25. </view>
  26. <view class="pictures">
  27. <image src="../../static/img/myimg/SiJi@3x.png" v-bind:class="picturesTwo" @click="oKSelected(2)">
  28. </image>
  29. <view style="margin: 0 auto;text-align: center;margin-top: -15px;" v-if="picturesTwo == 'picture1'">
  30. <image src="../../static/img/login/duihao2@3x.png" class="duihao"></image>
  31. </view>
  32. <view v-else style='margin: 0 auto;text-align: center;margin-top: -15px;width:18px;height:21px;'></view>
  33. <view class="title">司机</view>
  34. </view>
  35. <view class="pictures">
  36. <image src="../../static/img/myimg/LiangShang@3x.png" v-bind:class="picturesThree"
  37. @click="oKSelected(3)"></image>
  38. <view style="margin: 0 auto;text-align: center;margin-top: -15px;" v-if="picturesThree == 'picture1'">
  39. <image src="../../static/img/login/duihao2@3x.png" class="duihao"></image>
  40. </view>
  41. <view v-else style='margin: 0 auto;text-align: center;margin-top: -15px;width:18px;height:21px;'></view>
  42. <view class="title">粮商</view>
  43. </view>
  44. <view class="pictures">
  45. <image src="../../static/img/myimg/LiangNong@3x.png" v-bind:class="picturesFour" @click="oKSelected(4)">
  46. </image>
  47. <view style="margin: 0 auto;text-align: center;margin-top: -15px;" v-if="picturesFour == 'picture1'">
  48. <image src="../../static/img/login/duihao2@3x.png" class="duihao"></image>
  49. </view>
  50. <view v-else style='margin: 0 auto;text-align: center;margin-top: -15px;width:18px;height:21px;'></view>
  51. <view class="title">粮农</view>
  52. </view>
  53. </view>
  54. <view class="btn" @click="commit">
  55. 保存
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import {
  61. mapState
  62. } from 'vuex';
  63. export default {
  64. data() {
  65. return {
  66. pictures: "picture",
  67. picturesTwo: "picture",
  68. picturesThree: "picture",
  69. picturesFour: "picture",
  70. identityUrl: "",
  71. deptListurl: {},
  72. src: ''
  73. }
  74. },
  75. computed: {
  76. ...mapState(['hasLogin', 'userInfo'])
  77. },
  78. onLoad(option) {
  79. let url = this.userInfo.avatarUrl
  80. if(url){
  81. if(url == 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/162874144867649.png'){
  82. this.oKSelected(1)
  83. }else if(url == 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/162874149682940.png'){
  84. this.oKSelected(2)
  85. }else if(url == 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/1628741540162138.png'){
  86. this.oKSelected(3)
  87. }else if(url == 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/162874156836497.png'){
  88. this.oKSelected(4)
  89. }else{
  90. this.src = url
  91. this.identityUrl = url
  92. this.oKSelected(0)
  93. }
  94. }
  95. if (option.src) {
  96. this.src = option.src;
  97. this.identityUrl = option.src
  98. this.oKSelected(0)
  99. }
  100. },
  101. methods: {
  102. oKSelected(number) {
  103. if (number == 1) {
  104. if (this.pictures == "picture") {
  105. this.pictures = "picture1"
  106. this.picturesTwo = "picture"
  107. this.picturesThree = "picture"
  108. this.picturesFour = "picture"
  109. this.identityUrl = "https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/162874144867649.png"
  110. } else {
  111. this.pictures = "picture"
  112. }
  113. } else if (number == 2) {
  114. if (this.picturesTwo == "picture") {
  115. this.picturesTwo = "picture1"
  116. this.pictures = "picture"
  117. this.picturesThree = "picture"
  118. this.picturesFour = "picture"
  119. this.identityUrl = "https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/162874149682940.png"
  120. } else {
  121. this.picturesTwo = "picture"
  122. this.identityUrl = ""
  123. }
  124. } else if (number == 3) {
  125. if (this.picturesThree == "picture") {
  126. this.picturesThree = "picture1"
  127. this.pictures = "picture"
  128. this.picturesTwo = "picture"
  129. this.picturesFour = "picture"
  130. this.identityUrl = "https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/1628741540162138.png"
  131. } else {
  132. this.picturesThree = "picture"
  133. this.identityUrl = ""
  134. }
  135. } else if (number == 4) {
  136. if (this.picturesFour == "picture") {
  137. this.picturesFour = "picture1"
  138. this.pictures = "picture"
  139. this.picturesTwo = "picture"
  140. this.picturesThree = "picture"
  141. this.identityUrl = "https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/162874156836497.png"
  142. } else {
  143. this.picturesFour = "picture"
  144. this.identityUrl = ""
  145. }
  146. }else{
  147. this.pictures = "picture"
  148. this.picturesTwo = "picture"
  149. this.picturesThree = "picture"
  150. this.picturesFour = "picture"
  151. // this.identityUrl = ""
  152. }
  153. },
  154. upload() {
  155. uni.chooseImage({
  156. count: 1, // 默认9
  157. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  158. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  159. success(res) {
  160. const src = res.tempFilePaths[0];
  161. uni.redirectTo({
  162. url: '/pages/user/upload?src=' + src
  163. });
  164. }
  165. });
  166. },
  167. commit() {
  168. if (this.identityUrl == null || this.identityUrl == "") {
  169. this.$api.msg('请选择一张图片!')
  170. return
  171. }
  172. var that = this
  173. that.deptListurl.avatarUrl = that.identityUrl
  174. that.deptListurl.id = that.userInfo.id
  175. that.$api.doRequest('post', '/commonUser/editUserInfo', that.deptListurl).then(
  176. res => {
  177. if (res.data.code == 200) {
  178. uni.showToast({
  179. title: '修改成功!',
  180. icon: 'success',
  181. duration: 2000,
  182. success() {
  183. setTimeout(() => {
  184. that.userInfo.avatarUrl = that.identityUrl
  185. var _student = uni.getStorageSync('userInfo');
  186. _student.avatarUrl = that.identityUrl;
  187. uni.setStorageSync('userInfo', _student);
  188. var name = 'userInfo';
  189. var value = _student;
  190. that.$store.commit('$uStore', {
  191. name,
  192. value
  193. });
  194. // this.$api.msg('修改成功2!')
  195. uni.navigateBack({
  196. delta: 1
  197. })
  198. }, 2000)
  199. }
  200. })
  201. }
  202. })
  203. .catch(res => {
  204. if (res.data.errmsg) {
  205. uni.showToast({
  206. title: res.data.errmsg,
  207. icon: 'none',
  208. duration: 2000
  209. })
  210. } else {
  211. uni.showToast({
  212. title: "系统异常,请联系管理员",
  213. icon: 'none',
  214. duration: 2000
  215. })
  216. }
  217. });
  218. },
  219. }
  220. }
  221. </script>
  222. <style>
  223. .container {
  224. padding: 10px 10px 0px;
  225. background-color: #F5F6FA;
  226. }
  227. .headPortrait {
  228. width: 100%;
  229. background-color: #FFFFFF;
  230. border-radius: 20rpx;
  231. margin-top: 20rpx;
  232. }
  233. .picture {
  234. width: 70px;
  235. height: 70px;
  236. margin: 0 auto;
  237. margin-top: 10px;
  238. border: 2px solid transparent;
  239. }
  240. .picture1 {
  241. width: 70px;
  242. height: 70px;
  243. margin: 0 auto;
  244. border-radius: 35px;
  245. margin-top: 10px;
  246. border: 2px solid #22C572;
  247. }
  248. .title {
  249. text-align: center;
  250. margin: 9px 0;
  251. font-size: 14px;
  252. font-weight: 500;
  253. }
  254. .pictures {
  255. margin-left: 15px;
  256. }
  257. .duihao {
  258. width: 18px;
  259. height: 18px;
  260. text-align: center;
  261. margin: 0 auto;
  262. }
  263. .btn {
  264. width: 100%;
  265. height: 46px;
  266. background-color: #FFFFFF;
  267. text-align: center;
  268. color: #22C572;
  269. font-size: 17px;
  270. margin-top: 16px;
  271. border-radius: 30px;
  272. line-height: 50px;
  273. font-weight: 500;
  274. }
  275. .avatar-container {
  276. position: relative;
  277. text-align: center;
  278. padding-top: 50%;
  279. }
  280. .avatar {
  281. width: 230rpx;
  282. height: 230rpx;
  283. border: 1px dashed #afb3bf;
  284. border-radius: 50%;
  285. }
  286. .avatar1 {
  287. width: 230rpx;
  288. height: 230rpx;
  289. border-radius: 50%;
  290. }
  291. .plus {
  292. position: relative;
  293. width: 30px;
  294. margin: auto;
  295. top: 70px;
  296. }
  297. .item {
  298. text-align: center;
  299. margin: auto;
  300. margin-bottom: 20rpx;
  301. line-height: 60rpx;
  302. }
  303. </style>