carAdd.vue 6.3 KB

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