carAdd.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. this.$refs.uKeyboard.changeCarInputMode();
  76. if(this.carhelp.get("getElderModeClass") == "长辈模式") {
  77. this.elderStatus = true;
  78. } else {
  79. this.elderStatus = false;
  80. }
  81. },
  82. methods: {
  83. cancel() {
  84. this.keyShow = false;
  85. },
  86. confirm() {
  87. this.keyShow = false;
  88. },
  89. keyClick() {
  90. this.keyShow = true;
  91. uni.hideKeyboard();
  92. },
  93. // 按键被点击(点击退格键不会触发此事件)
  94. valChange(val) {
  95. // 将每次按键的值拼接到form.carNum变量中,注意+=写法
  96. if(this.form.carNum.length < 8) {
  97. this.form.carNum += val;
  98. //(this.form.carNum);
  99. if(this.form.carNum.length == 1) {
  100. this.$refs.uKeyboard.changeCarInputMode();
  101. }
  102. if(this.form.carNum.length == 8) {
  103. this.carName = '新能源车';
  104. } else if (this.form.carNum.length == 7) {
  105. this.carName = '燃油车';
  106. } else {
  107. this.carName = '';
  108. }
  109. }
  110. },
  111. // 退格键被点击
  112. backspace() {
  113. // 删除form.carNum的最后一个字符
  114. if(this.form.carNum.length) this.form.carNum = this.form.carNum.substr(0, this.form.carNum.length - 1);
  115. //(this.form.carNum);
  116. var aaa = this.$refs.uKeyboard.changeCarInputValue();
  117. if(this.form.carNum.length == 0 && aaa) {
  118. this.$refs.uKeyboard.changeCarInputMode();
  119. }
  120. if(this.form.carNum.length == 8) {
  121. this.carName = '新能源车';
  122. } else if (this.form.carNum.length == 7) {
  123. this.carName = '燃油车';
  124. } else {
  125. this.carName = '';
  126. }
  127. },
  128. getCarList() {
  129. uni.showLoading({
  130. title: "加载中",
  131. mask: true,
  132. })
  133. userApi.regUserCarList().then((res) => {
  134. uni.hideLoading();
  135. this.carList = res.data;
  136. for(var i=0;i<this.carList.length;i++) {
  137. var carId = this.carList[i].id
  138. if(this.form.id == carId) {
  139. this.form.carNum = this.carList[i].carNum;
  140. this.form.defaultFlag = this.carList[i].defaultFlag;
  141. if(this.form.carNum.length == 8) {
  142. this.carName = '新能源车';
  143. } else if (this.form.carNum.length == 7) {
  144. this.carName = '燃油车';
  145. } else {
  146. this.carName = '';
  147. }
  148. }
  149. }
  150. }).catch(error => {
  151. uni.showToast({
  152. title: error,
  153. icon: "none"
  154. })
  155. })
  156. },
  157. showDelete() {
  158. this.show = true;
  159. this.keyShow = false;
  160. },
  161. confirmDelete() {
  162. uni.showLoading({
  163. title: "加载中",
  164. mask: true,
  165. })
  166. userApi.deleteRegUserCar({
  167. id: this.form.id
  168. }).then((res) => {
  169. uni.hideLoading();
  170. this.show = false;
  171. uni.navigateBack({
  172. //url: '/pages/user/car/index'
  173. })
  174. }).catch(error => {
  175. uni.showToast({
  176. title: error,
  177. icon: "none"
  178. })
  179. })
  180. },
  181. keepCar() {
  182. this.keyShow = false;
  183. if(this.form.carNum.length != 8) {
  184. uni.showToast({
  185. title:"请填写新能源车牌"
  186. })
  187. return
  188. }
  189. uni.showLoading({
  190. title: "加载中",
  191. mask: true,
  192. })
  193. userApi.addRegUserCar(this.form).then((res) => {
  194. uni.hideLoading();
  195. if(this.code == 'A') {
  196. uni.reLaunch({
  197. url: '/pages/searchPile/stationAndPile/chargingPileDetails?id=' + this.codeId
  198. })
  199. } else {
  200. uni.navigateBack({
  201. // url: '/pages/user/car/index'
  202. })
  203. }
  204. }).catch(error => {
  205. uni.showToast({
  206. title: error,
  207. icon: "none"
  208. })
  209. })
  210. }
  211. }
  212. }
  213. </script>
  214. <style>
  215. page{
  216. background: #fff;
  217. }
  218. </style>
  219. <style lang="scss" scoped>
  220. .slot-wrap{
  221. flex: 1;
  222. }
  223. .navBtn{
  224. float: right;
  225. margin-right: 15px;
  226. color:#FF6666;
  227. }
  228. .carDet{
  229. padding: 0 16px;
  230. }
  231. .login-btn {
  232. margin: 28px ;
  233. background-color:#00B962!important;
  234. border-color: #00B962!important;
  235. color:#fff!important;
  236. }
  237. </style>