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