edit.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <view class="edit">
  3. <navbar ref="navbar" backColor="#666" :config="config"></navbar>
  4. <form @submit="formSubmit">
  5. <view class="middle">
  6. <view class="item">
  7. <view class="left">
  8. 头像
  9. </view>
  10. <view class="right">
  11. <image v-if="unserInfo.head_photo" :src="unserInfo.head_photo" @click="uploadImg" mode="aspectFill">
  12. </image>
  13. <image v-else :src="imgUrl+'/head-on.png'" mode="aspectFill" @click="uploadImg"></image>
  14. <text class="iconfont">&#xe6c7;</text>
  15. </view>
  16. </view>
  17. <view class="name-item">
  18. <view class="name-left">
  19. 姓名
  20. </view>
  21. <view class="name-right">
  22. <input type="text" :value="unserInfo.real_name" maxlength="32" @input="onName"
  23. class="my-name" />
  24. <text class="iconfont">&#xe6c7;</text>
  25. </view>
  26. </view>
  27. <view class="item">
  28. <view class="left">
  29. 手机号
  30. </view>
  31. <view class="right">
  32. <view class="phone">
  33. {{unserInfo.mobile}}
  34. </view>
  35. </view>
  36. </view>
  37. <view class="item">
  38. <view class="left">
  39. 性别
  40. </view>
  41. <view class="right" v-if="platform.length>0">
  42. <picker class="choice" @change="bindPickerChange" :value="unserInfo.gender" :range="platform"
  43. range-key="name">
  44. <view class="uni-input">{{platform[index].name}}<text class="iconfont">&#xe6c7;</text>
  45. </view>
  46. </picker>
  47. </view>
  48. </view>
  49. <view class="item">
  50. <view class="left">
  51. 生日
  52. </view>
  53. <view class="right" style="flex: 1;">
  54. <picker style="flex: 1;height: 38rpx;text-align: right;" mode="date" :value="date"
  55. :start="startDate" :end="endDate" @change="bindDateChange">
  56. <view class="uni-input">{{date ? date : '未知'}}</view>
  57. </picker>
  58. <text class="iconfont">&#xe6c7;</text>
  59. </view>
  60. </view>
  61. <!-- <view class="item">
  62. <view class="left">
  63. 等级
  64. </view>
  65. <view class="right">
  66. <view class="name">
  67. {{unserInfo.role_name}}
  68. </view>
  69. </view>
  70. </view> -->
  71. </view>
  72. <view class="submit-top">
  73. <button class="submit" form-type="submit">
  74. 修改资料
  75. </button>
  76. </view>
  77. </form>
  78. </view>
  79. </template>
  80. <script>
  81. function getDate(type) {
  82. const date = new Date();
  83. let year = date.getFullYear();
  84. let month = date.getMonth() + 1;
  85. let day = date.getDate();
  86. if (type === 'start') {
  87. year = year - 150;
  88. } else if (type === 'end') {
  89. year = year + 150;
  90. }
  91. month = month > 9 ? month : '0' + month;;
  92. day = day > 9 ? day : '0' + day;
  93. return `${year}-${month}-${day}`;
  94. }
  95. import {
  96. appTheeLbs
  97. } from "@/api/basic.js"
  98. import {
  99. myInfo,
  100. updateInfo
  101. } from "@/api/login.js"
  102. export default {
  103. data() {
  104. return {
  105. config: {
  106. back: true, //false是tolbar页面 是则不写
  107. title: '修改资料',
  108. color: '#1A1A1A',
  109. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  110. backgroundColor: [1, "#fff"],
  111. statusBarFontColor: '#1A1A1A',
  112. },
  113. platform: [{
  114. name: '女'
  115. },
  116. {
  117. name: '男'
  118. },
  119. {
  120. name: "保密"
  121. },
  122. ],
  123. imgSize: 4,
  124. index: 0, //性别
  125. date: getDate({
  126. format: true
  127. }),
  128. // date: '',
  129. startDate: getDate('start'),
  130. endDate: getDate('end'),
  131. time: '12:01',
  132. newProvinceDataList: [
  133. [],
  134. [],
  135. []
  136. ],
  137. unserInfo: {},
  138. ossData: null,
  139. imgType: ['jpeg', 'png', 'jpg'],
  140. imgUrl: this.$mConfig.staticUrl
  141. }
  142. },
  143. //组件
  144. //获得省市区
  145. onShow() {
  146. this.$http.get(appTheeLbs).then(res => {
  147. let provincesList = res.tree.children
  148. for (let i = 0; i < provincesList.length; i++) {
  149. this.newProvinceDataList[0].push(provincesList[i]);
  150. }
  151. })
  152. //取shop的值
  153. let shop = uni.getStorageSync("shop")
  154. },
  155. onLoad() {
  156. this.getUserInfo();
  157. // this.formDataGet();
  158. },
  159. methods: {
  160. //上传凭证
  161. formDataGet() {
  162. let that = this
  163. uni.request({
  164. //url: 'https://pm.lidashine.com/get-oss-sign', //oss获取参数接口地址。
  165. // url: this.$mConfig.baseUrl + '/fileMgr/v1/oss/getOssSign',
  166. url: 'http://192.168.0.101:9020/fileMgr/v1/oss/getOssSign',
  167. complete: (result) => {
  168. console.log(result, 'result')
  169. let res = JSON.parse(result.data.data);
  170. console.log('res===>', res)
  171. that.ossData = res
  172. }
  173. })
  174. },
  175. //获取登录的用户信息
  176. getUserInfo() {
  177. this.$http.get(myInfo).then(res => {
  178. this.index = res.data.gender //男女
  179. this.date = res.data.birthday;
  180. this.unserInfo = res.data;
  181. })
  182. },
  183. //修改个人信息
  184. formSubmit(e) {
  185. let target = e.detail.value
  186. let mobile = this.unserInfo.mobile
  187. let gender = this.index.toString()
  188. let param = {
  189. real_name: this.unserInfo.real_name,
  190. head_photo: this.unserInfo.head_photo, //this.unserInfo.head_photo, //图像
  191. gender: gender, //性别
  192. birthday: this.date, //生日
  193. }
  194. this.$http.put(updateInfo, param)
  195. .then(res => {
  196. if (res.code == 200) {
  197. this.$mUtil.toast("修改成功")
  198. let aa = uni.getStorageSync("personal", res.data)
  199. } else {
  200. this.$mUtil.toast("修改失败")
  201. }
  202. })
  203. },
  204. //更换图片
  205. updataImg(filePath, nameStr) {
  206. console.log(filePath, nameStr)
  207. let date = new Date();
  208. let that = this
  209. let allData = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate()
  210. let shopid = uni.getStorageSync('shop')
  211. let id = 0
  212. if (!shopid) {
  213. id = 0
  214. } else {
  215. id = shopid.id
  216. }
  217. let key = 'img/' + id + '/' + this.type + '/' + allData + '/' + nameStr
  218. uni.uploadFile({
  219. // url: this.$mConfig.baseUrl+ '/minio/upload',
  220. url: this.$mConfig.baseUrl+ '/sys/oss/upload',
  221. filePath: filePath,
  222. fileType: 'image',
  223. name: 'file',
  224. success: (res) => {
  225. uni.hideLoading();
  226. if (res.statusCode != 200) {
  227. return;
  228. }
  229. let resObj = JSON.parse(res.data);
  230. let imgurl = resObj.data.url;
  231. uni.showToast({
  232. title: '上传成功',
  233. icon: 'success',
  234. duration: 1000
  235. })
  236. that.unserInfo.head_photo = imgurl
  237. // alert(ossRes.host+"/"+encodeURIComponent(fileName));
  238. },
  239. fail: (err) => {
  240. uni.hideLoading();
  241. uni.showModal({
  242. content: err.errMsg,
  243. showCancel: false
  244. });
  245. }
  246. });
  247. },
  248. //更换图片
  249. uploadImg() {
  250. let that = this
  251. uni.chooseImage({
  252. count: 1, //默认9
  253. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  254. sourceType: ['album'], //从相册选择
  255. success: (res) => {
  256. let that = this
  257. if (res) {
  258. let filePath = res.tempFilePaths[0]
  259. let nameStr = that.random_string(8) + '.' + res.tempFilePaths[0].split('.').pop();
  260. if (res.tempFiles) {
  261. for (let item of res.tempFiles) {
  262. if (item.size > (that.imgSize * 1024 * 1024)) {
  263. uni.showToast({
  264. title: `图片不能大于${that.imgSize}M`,
  265. icon: 'none'
  266. })
  267. return false;
  268. }
  269. if (item.type) {
  270. let r = that.imgType.some(v => {
  271. let type = item.type.split('/');
  272. if (type.length)
  273. return (v === type[1]);
  274. });
  275. if (!r) {
  276. uni.showToast({
  277. title: `只允许上传${that.imgType}的类型`,
  278. icon: 'none'
  279. })
  280. return false;
  281. }
  282. }
  283. }
  284. }
  285. that.updataImg(filePath, nameStr)
  286. }
  287. }
  288. });
  289. },
  290. random_string(len) {
  291. len = len || 32;
  292. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz123456789';
  293. var maxPos = chars.length;
  294. var pwd = '';
  295. for (let i = 0; i < len; i++) {
  296. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  297. }
  298. return pwd;
  299. },
  300. //修改昵称
  301. onName(e) {
  302. this.unserInfo.real_name = e.detail.value
  303. },
  304. bindPickerChange: function(e) {
  305. this.index = e.detail.value
  306. },
  307. bindDateChange: function(e) {
  308. this.date = e.detail.value
  309. },
  310. }
  311. }
  312. </script>
  313. <style scoped lang="scss">
  314. .name-item {
  315. display: flex;
  316. align-items: center;
  317. justify-content: space-between;
  318. border-bottom: 1rpx solid #E6E6E6;
  319. padding: 34rpx 0 30rpx 0;
  320. .name-right {
  321. flex: 1;
  322. padding-left: 30rpx;
  323. text-align: right;
  324. display: flex;
  325. align-items: center;
  326. .my-name {
  327. width: 100%;
  328. }
  329. }
  330. }
  331. .submit-top {
  332. width: 100%;
  333. padding: 0 30rpx;
  334. position: fixed;
  335. bottom: 60rpx;
  336. }
  337. .submit {
  338. text-align: center;
  339. border-radius: 43rpx;
  340. margin-top: 350rpx;
  341. font-size: 36rpx;
  342. color: #ffffff;
  343. font-weight: 400;
  344. background-color: #3D93FC;
  345. }
  346. .distance {
  347. height: 10rpx;
  348. background-color: #F5F5F5;
  349. }
  350. .middle {
  351. padding: 0 30rpx;
  352. .item {
  353. display: flex;
  354. align-items: center;
  355. justify-content: space-between;
  356. border-bottom: 1rpx solid #E6E6E6;
  357. padding: 34rpx 0 30rpx 0;
  358. .left {
  359. font-size: 28rpx;
  360. color: #1A1A1A;
  361. font-weight: 400;
  362. }
  363. .right {
  364. display: flex;
  365. align-items: center;
  366. .my-phone {
  367. text-align: right;
  368. }
  369. .my-name {
  370. text-align: right;
  371. }
  372. .name {
  373. font-size: 28rpx;
  374. color: #1A1A1A;
  375. font-weight: 400;
  376. }
  377. image {
  378. width: 76rpx;
  379. height: 76rpx;
  380. border-radius: 50%;
  381. }
  382. .iconfont {
  383. margin-left: 15rpx;
  384. }
  385. }
  386. }
  387. }
  388. </style>