carAdd.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view >
  3. <ujp-navbar title="车辆修改">
  4. <view class="slot-wrap">
  5. <span class="navBtn oldTextjp2" oldstyle="font-size: 16px;" @click="showDelete">删除</span>
  6. </view>
  7. </ujp-navbar>
  8. <view v-if="false">
  9. <view>
  10. <u-modal v-model="show" @confirm="confirmDelete" confirm-color="#fa3534" :show-cancel-button="true" ref="uModal" :asyncClose="true" :title="title"
  11. :content="content" :confirm-text="confirmText"></u-modal>
  12. </view>
  13. <view class="carDet">
  14. <u-form :model="form" ref="uForm">
  15. <ucarkeyboard ref="uKeyboard" mode="car" @confirm="confirm" @cancel="cancel" v-show="keyShow" @change="valChange" @backspace="backspace"></ucarkeyboard>
  16. <u-form-item label="车牌号码" label-width="200rpx" :label-style="elderStatus ? {fontSize: '18px'} : {}">
  17. <u-input input-align="right" placeholder="请输入车牌号" v-model="form.carNum" :custom-style="elderStatus ? {fontSize: '18px'} : {}" @click="keyClick" />
  18. </u-form-item>
  19. <u-form-item v-show="false" label="车辆类型" label-width="200rpx" :label-style="elderStatus ? {fontSize: '18px'} : {}">
  20. <u-input input-align="right" v-model="carName" :custom-style="elderStatus ? {fontSize: '18px'} : {}" placeholder="请输入正确车牌号" disabled />
  21. </u-form-item>
  22. <!-- <u-form-item label="设为默认车辆" label-width="230rpx" :label-style="elderStatus ? {fontSize: '18px'} : {}">
  23. <u-switch slot="right" v-model="form.defaultFlag"></u-switch>
  24. </u-form-item> -->
  25. </u-form>
  26. </view>
  27. <u-button class="login-btn" type="success" shape="circle" @click="keepCar">保存</u-button>
  28. <!-- <p class="car-num" style="padding: 10px 40px;" >根据平台要求,车牌号码输入后暂时<span style="color:red">不可以修改</span>,后续修改需要联系客服人员,请认真填写</p>
  29. -->
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import * as userApi from '@/apis/user.js'
  35. import ucarkeyboard from '@/components/Ucarkeyboard.vue'
  36. export default {
  37. components: {
  38. ucarkeyboard
  39. },
  40. data() {
  41. return {
  42. carName: '',
  43. keyShow: false,
  44. show: false,
  45. title: '删除车辆',
  46. content: '是否删除此车牌号?',
  47. confirmText: '删除',
  48. form: {
  49. id: '',
  50. carNum: '',
  51. defaultFlag: true,
  52. },
  53. carList: [],
  54. elderStatus: false,
  55. }
  56. },
  57. onLoad(op) {
  58. if (op.jpcode) {
  59. var str1 = op.jpcode.slice(0, 19);
  60. var str2 = op.jpcode.slice(20, 21);
  61. var str3 = op.jpcode.slice(22);
  62. if (str1 == 'jp_team51_charge_id') {
  63. if (str2 == 'A') {
  64. this.code = str2;
  65. this.codeId = str3;
  66. }
  67. }
  68. }
  69. if(op.id){
  70. this.form.id = op.id;
  71. this.getCarList();
  72. }
  73. },
  74. onReady() {
  75. if(this.$refs.uKeyboard){
  76. this.$refs.uKeyboard.changeCarInputMode();
  77. }
  78. if(this.carhelp.get("getElderModeClass") == "长辈模式") {
  79. this.elderStatus = true;
  80. } else {
  81. this.elderStatus = false;
  82. }
  83. },
  84. methods: {
  85. cancel() {
  86. this.keyShow = false;
  87. },
  88. confirm() {
  89. this.keyShow = false;
  90. },
  91. keyClick() {
  92. this.keyShow = true;
  93. uni.hideKeyboard();
  94. },
  95. // 按键被点击(点击退格键不会触发此事件)
  96. valChange(val) {
  97. // 将每次按键的值拼接到form.carNum变量中,注意+=写法
  98. if(this.form.carNum.length < 8) {
  99. this.form.carNum += val;
  100. //(this.form.carNum);
  101. if(this.form.carNum.length == 1) {
  102. this.$refs.uKeyboard.changeCarInputMode();
  103. }
  104. if(this.form.carNum.length == 8) {
  105. this.carName = '新能源车';
  106. } else if (this.form.carNum.length == 7) {
  107. this.carName = '燃油车';
  108. } else {
  109. this.carName = '';
  110. }
  111. }
  112. },
  113. // 退格键被点击
  114. backspace() {
  115. // 删除form.carNum的最后一个字符
  116. if(this.form.carNum.length) this.form.carNum = this.form.carNum.substr(0, this.form.carNum.length - 1);
  117. //(this.form.carNum);
  118. var aaa = this.$refs.uKeyboard.changeCarInputValue();
  119. if(this.form.carNum.length == 0 && aaa) {
  120. this.$refs.uKeyboard.changeCarInputMode();
  121. }
  122. if(this.form.carNum.length == 8) {
  123. this.carName = '新能源车';
  124. } else if (this.form.carNum.length == 7) {
  125. this.carName = '燃油车';
  126. } else {
  127. this.carName = '';
  128. }
  129. },
  130. getCarList() {
  131. uni.showLoading({
  132. title: "加载中",
  133. mask: true,
  134. })
  135. userApi.regUserCarList().then((res) => {
  136. uni.hideLoading();
  137. this.carList = res.data;
  138. for(var i=0;i<this.carList.length;i++) {
  139. var carId = this.carList[i].id
  140. if(this.form.id == carId) {
  141. this.form.carNum = this.carList[i].carNum;
  142. this.form.defaultFlag = this.carList[i].defaultFlag;
  143. if(this.form.carNum.length == 8) {
  144. this.carName = '新能源车';
  145. } else if (this.form.carNum.length == 7) {
  146. this.carName = '燃油车';
  147. } else {
  148. this.carName = '';
  149. }
  150. }
  151. }
  152. }).catch(error => {
  153. uni.showToast({
  154. title: error,
  155. icon: "none"
  156. })
  157. })
  158. },
  159. showDelete() {
  160. this.show = true;
  161. this.keyShow = false;
  162. },
  163. confirmDelete() {
  164. uni.showLoading({
  165. title: "加载中",
  166. mask: true,
  167. })
  168. userApi.deleteRegUserCar({
  169. id: this.form.id
  170. }).then((res) => {
  171. uni.hideLoading();
  172. this.show = false;
  173. uni.navigateBack({
  174. //url: '/pages/user/car/index'
  175. })
  176. }).catch(error => {
  177. uni.showToast({
  178. title: error,
  179. icon: "none"
  180. })
  181. })
  182. },
  183. keepCar() {
  184. this.keyShow = false;
  185. if(this.form.carNum.length != 8) {
  186. uni.showToast({
  187. title:"请填写新能源车牌"
  188. })
  189. return
  190. }
  191. uni.showLoading({
  192. title: "加载中",
  193. mask: true,
  194. })
  195. userApi.addRegUserCar(this.form).then((res) => {
  196. uni.hideLoading();
  197. if(this.code == 'A') {
  198. uni.reLaunch({
  199. url: '/pages/searchPile/stationAndPile/chargingPileDetails?id=' + this.codeId
  200. })
  201. } else {
  202. uni.navigateBack({
  203. // url: '/pages/user/car/index'
  204. })
  205. }
  206. }).catch(error => {
  207. uni.showToast({
  208. title: error,
  209. icon: "none"
  210. })
  211. })
  212. }
  213. }
  214. }
  215. </script>
  216. <style>
  217. page{
  218. background: #fff;
  219. }
  220. </style>
  221. <style lang="scss" scoped>
  222. .slot-wrap{
  223. flex: 1;
  224. }
  225. .navBtn{
  226. float: right;
  227. margin-right: 15px;
  228. color:#FF6666;
  229. }
  230. .carDet{
  231. padding: 0 16px;
  232. }
  233. .login-btn {
  234. margin: 28px ;
  235. background-color:#00B962!important;
  236. border-color: #00B962!important;
  237. color:#fff!important;
  238. }
  239. </style>