completeInfo.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <view>
  3. <u-navbar title="完善信息">
  4. <view slot="right" @click="gotoLink" style=" margin-right: 10px;"> 跳过</view>
  5. </u-navbar>
  6. <view class="data">
  7. <view class="data-img">
  8. <view class="data-icon">
  9. <u-icon name="camera-fill" custom-prefix="custom-icon" color="#fff" size="32"></u-icon>
  10. </view>
  11. <u-avatar :src="form.headImg+'?x-oss-process=image/resize,m_fill,w_256,h_256'" size="216" @click="uploadPhoto" /></u-avatar>
  12. </view>
  13. <view class="data-input">
  14. <u-form :model="form" ref="uForm" >
  15. <u-form-item label-position="top" label="昵称"><u-input v-model="form.nickName" placeholder="请填写昵称"/></u-form-item>
  16. </u-form>
  17. </view>
  18. <p class="car-num" @tap="keyShow=!keyShow" >车牌号码<span style="color: #9e9e9e;float: right;padding-right: 10px;">(点击唤起键盘)</span></p>
  19. <view class="key-input"
  20. @tap="keyShow=!keyShow">
  21. <u-message-input :focus="true" :value="form.carNum" :maxlength="maxlength" :disabled-keyboard="true"></u-message-input>
  22. </view>
  23. <view class="default" >
  24. <u-checkbox-group>
  25. <u-checkbox class="tips" v-model="form.defaultFlag" @change="checkboxChange()" shape="circle" >设为默认车辆</u-checkbox>
  26. </u-checkbox-group>
  27. </view>
  28. <u-button class="login-btn" v-show="!keyShow"
  29. @click="keepCar"
  30. type="success" shape="circle" >完成</u-button>
  31. <ucarkeyboard ref="uKeyboard"
  32. style=" z-index: 999;"
  33. :style="!keyShow?'display: none':''"
  34. mode="car" :confirmBtn="false" :mask-close-able="false" :tooltip="false" v-show="keyShow" @change="valChange" @backspace="backspace">
  35. <view style="
  36. text-align: center;
  37. font-size: 18px;
  38. ">
  39. <span>车牌号:{{form.carNum}}</span>
  40. <span
  41. @tap="keyShow=!keyShow"
  42. style="
  43. float: right;
  44. padding-right: 10px;
  45. color: #41a863;
  46. " >确定</span>
  47. </view>
  48. </ucarkeyboard>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import * as userApi from '@/apis/user.js'
  54. import ucarkeyboard from '@/components/Ucarkeyboard.vue'
  55. import * as loginApi from '@/apis/login.js'
  56. export default {
  57. components: {
  58. ucarkeyboard
  59. },
  60. data() {
  61. return {
  62. maxlength:8,
  63. keyShow: false,
  64. isLogin:false,
  65. code:"",
  66. codeId:"",
  67. form: {
  68. nickName: '',
  69. headImg: '',
  70. carNum: '鄂',
  71. defaultFlag: true,
  72. },
  73. }
  74. },
  75. onLoad(op) {
  76. if (op.jpcode) {
  77. var str1 = op.jpcode.slice(0, 19);
  78. var str2 = op.jpcode.slice(20, 21);
  79. var str3 = op.jpcode.slice(22);
  80. if (str1 == 'jp_team51_charge_id') {
  81. if (str2 == 'A') {
  82. this.code = str2;
  83. this.codeId = str3;
  84. }
  85. }
  86. }
  87. if(op.login){
  88. this.isLogin=true;
  89. }
  90. },
  91. onReady() {
  92. this.$refs.uKeyboard.changeCarInputMode();
  93. this.getUserInfo();
  94. },
  95. methods: {
  96. getUserInfo() {
  97. uni.showLoading({
  98. title: "加载中",
  99. mask: true,
  100. })
  101. loginApi.findByOpenId({
  102. openId: this.carhelp.getOpenId()
  103. }).then((res) => {
  104. uni.hideLoading();
  105. this.form.nickName = res.data.regUser.nickName;
  106. this.form.headImg = res.data.regUser.headImg;
  107. }).catch(error => {
  108. uni.showToast({
  109. title: error,
  110. icon: "none"
  111. })
  112. })
  113. },
  114. uploadPhoto() {
  115. let _self = this;
  116. const crop = {
  117. quality: 100,
  118. width: 600,
  119. height: 600,
  120. resize: true
  121. };
  122. // 上传图片
  123. uni.chooseImage({
  124. count: 1,
  125. crop,
  126. success: async (res) => {
  127. console.log(res);
  128. let tempFile = res.tempFiles[0],
  129. avatar_file = {
  130. // #ifdef H5
  131. extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1],
  132. // #endif
  133. // #ifndef H5
  134. extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1]
  135. // #endif
  136. },
  137. filePath = res.tempFilePaths[0]
  138. // #ifndef APP-PLUS
  139. console.log(`filePath=${filePath}`)
  140. //非app端用前端组件剪裁头像,app端用内置的原生裁剪
  141. let fileData = await new Promise((callback) => {
  142. uni.navigateTo({
  143. url: '/pages/user/cropImage?path=' + filePath +
  144. `&options=${JSON.stringify(crop)}`,
  145. animationType: "fade-in",
  146. events: {
  147. success: url => {
  148. callback(url)
  149. }
  150. }
  151. });
  152. })
  153. // #endif
  154. //返回 base64 图片
  155. console.log(fileData);
  156. var token = _self.carhelp.getToken()
  157. uni.showLoading({
  158. title: '上传中'
  159. });
  160. uni.request({
  161. url: process.car.BASE_URL + "uploadBase64",
  162. method: 'POST',
  163. data: {
  164. photoBase64Data: fileData
  165. },
  166. header: {
  167. 'Authorization': token,
  168. 'content-type': 'application/x-www-form-urlencoded'
  169. },
  170. success: (res) => {
  171. let jsonData = res.data;
  172. _self.form.headImg = jsonData.data;
  173. uni.hideLoading();
  174. }
  175. });
  176. }
  177. });
  178. },
  179. gotoLink(){
  180. if (this.code == 'A') {
  181. uni.redirectTo({
  182. url: '/pages/searchPile/stationAndPile/chargingPileDetails?id=' + this.codeId
  183. })
  184. } else if (this.isLogin){
  185. uni.redirectTo({
  186. url: '/pages/index/index'
  187. })
  188. }else {
  189. uni.navigateBack({
  190. url: '/pages/user/car/index'
  191. })
  192. }
  193. },
  194. checkboxChange() {
  195. this.form.defaultFlag = !this.form.defaultFlag;
  196. },
  197. // 按键被点击(点击退格键不会触发此事件)
  198. valChange(val) {
  199. if(this.form.carNum.length>=this.maxlength){
  200. return
  201. }
  202. // 将每次按键的值拼接到form.carNum变量中,注意+=写法
  203. this.form.carNum += val;
  204. console.log(this.form.carNum);
  205. if(this.form.carNum.length == 1) {
  206. this.$refs.uKeyboard.changeCarInputMode();
  207. }
  208. },
  209. // 退格键被点击
  210. backspace() {
  211. // 删除form.carNum的最后一个字符
  212. if (this.form.carNum.length) this.form.carNum = this.form.carNum.substr(0, this.form.carNum.length - 1);
  213. console.log(this.form.carNum);
  214. var aaa = this.$refs.uKeyboard.changeCarInputValue();
  215. if(this.form.carNum.length == 0 && aaa) {
  216. this.$refs.uKeyboard.changeCarInputMode();
  217. }
  218. },
  219. keepCar() {
  220. console.log(this.form)
  221. uni.showLoading({
  222. title: "加载中",
  223. mask: true,
  224. })
  225. userApi.perfectPersonInformation(this.form).then((res) => {
  226. uni.hideLoading();
  227. this.gotoLink()
  228. }).catch(error => {
  229. uni.showToast({
  230. title: error,
  231. icon: "none"
  232. })
  233. })
  234. }
  235. }
  236. }
  237. </script>
  238. <style>
  239. page{
  240. background: #fff;
  241. }
  242. </style>
  243. <style lang="scss" scoped>
  244. .u-char-item{
  245. width: 29px !important;
  246. }
  247. .skip{
  248. margin-left: 81.3%;
  249. }
  250. .data-icon{
  251. height: 28px;
  252. width: 28px;
  253. background-color: #00B962;
  254. border-radius: 14px;
  255. border: 2px solid #fff;
  256. text-align: center;
  257. line-height: 24px;
  258. position: absolute;
  259. z-index: 999;
  260. right: 0;
  261. bottom:0px
  262. }
  263. .data-img{
  264. margin: 30px auto;
  265. height: 108px;
  266. width: 108px;
  267. position: relative;
  268. }
  269. .data-input{
  270. margin: 0 40px;
  271. }
  272. .login-btn {
  273. margin: 28px ;
  274. background-color:#00B962!important;
  275. border-color: #00B962!important;
  276. color:#fff!important;
  277. }
  278. .car-num{
  279. padding: 40px 0 0 40px;
  280. line-height: 18px;
  281. }
  282. .key-input {
  283. padding-top: 19px;
  284. }
  285. .default {
  286. margin: 16px 28px;
  287. }
  288. /deep/.u-char-item {
  289. width: 30px !important;
  290. height: 40px !important;
  291. font-size: 18px !important;
  292. }
  293. </style>