completeInfo.vue 9.0 KB

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