activation.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="container-view">
  3. <view class="return-info flex-row flex-between">
  4. <view class="return-top">
  5. <view>车型:{{car_model}}</view>
  6. <view>车牌:{{plate_number}}</view>
  7. </view>
  8. <view><img :src="model_image" /></view>
  9. </view>
  10. <view class="pictures-info">
  11. <view>车辆照片</view>
  12. <!-- <view>这里是关于激活车辆照片的文案描述,这里是关于激活车辆照片的文案描述</view> -->
  13. <uploader :car_info="car_imgs" @update-car-images="handleCarImagesUpdate"></uploader>
  14. <view @tap="submitEnabled" class="pictures-btn">激活车辆</view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import uploader from '@/component/uploader/uploader';
  20. const http = require('../../common/http.js');
  21. const config = require('../../common/config.js');
  22. const common = require('../../common/common.js');
  23. export default {
  24. components: {
  25. uploader
  26. },
  27. data() {
  28. return {
  29. isJumpReturn:true,
  30. isCustomJump: true,
  31. carInfo: {},
  32. plate_number: '',
  33. order_sn: '',
  34. model_image: '',
  35. car_model: '',
  36. return_imgs: [],
  37. car_imgs: [],
  38. model_image_list: ''
  39. };
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function(options) {
  45. this.plate_number = options.plate_number ? options.plate_number : ''
  46. this.isJumpReturn = options.isJumpReturn ? false : true
  47. if (options.order_sn && options.return_imgs) { // 预约租车
  48. this.order_sn = options.order_sn ? options.order_sn : ''
  49. this.car_model = options.car_model ? options.car_model : ''
  50. this.model_image = options.model_image ? options.model_image : ''
  51. // 处理上传图片格式问题
  52. this.return_imgs = options.return_imgs ? JSON.parse(decodeURIComponent(options.return_imgs)) : ''
  53. this.handleImage()
  54. } else { //扫码租车
  55. this.loadCarInfo()
  56. }
  57. },
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow: function() {
  62. this.isCustomJump = true
  63. },
  64. onUnload: function () {
  65. if(this.isCustomJump && this.isJumpReturn){
  66. uni.switchTab({
  67. url: '/pages/my/my' // 假设首页的路径是/pages/home/home
  68. });
  69. }
  70. },
  71. methods: {
  72. loadCarInfo() {
  73. const me = this
  74. const myLocation = uni.getStorageSync('user_current_location')
  75. const pData = {
  76. longitude: myLocation.longitude,
  77. latitude: myLocation.latitude,
  78. plate_number: me.plate_number
  79. }
  80. http.postApi(config.API_DAYHIRE_CAR_CAR_INFO, pData, function(resp) {
  81. if (resp.data.code === 200) {
  82. me.orderInfo = resp.data.data
  83. me.order_sn = me.orderInfo.order_sn
  84. me.model_image_list = me.orderInfo.model_info.model_images.split(
  85. ',') // 处理图片格式问题,确保能正确显示图片。
  86. me.model_image = me.model_image_list[0]
  87. me.return_imgs = me.orderInfo.return_imgs
  88. me.handleImage()
  89. } else {
  90. // 默认返回首页再提示报错
  91. me.isCustomJump = false
  92. uni.reLaunch({
  93. url: '/pages/index/index'
  94. })
  95. common.simpleToast(resp.data.msg)
  96. }
  97. })
  98. },
  99. handleImage() {
  100. const length = this.return_imgs.list ? this.return_imgs.list.length : 0
  101. const num = this.return_imgs.num - 0
  102. for (let i = length; i < num; i++) { // 循环num-length次,每次添加一个空对象到数组中
  103. this.return_imgs.list.push({});
  104. }
  105. this.car_imgs = this.return_imgs.list.map(item => {
  106. if (!item.hasOwnProperty('img_url')) {
  107. item.img_url = ""
  108. }
  109. if (!item.hasOwnProperty('title')) {
  110. item.title = ""
  111. }
  112. if (!item.hasOwnProperty('url')) {
  113. item.url = ""
  114. }
  115. return item
  116. })
  117. },
  118. handleCarImagesUpdate(updatedImages) {
  119. // 这里会接收到子组件传来的更新后的图片URL数组
  120. this.car_imgs = updatedImages
  121. },
  122. submitEnabled() {
  123. const me = this
  124. const _image_list = this.car_imgs.map(item => item.img_url)
  125. if (_image_list.includes('' || "")) return common.simpleToast('请上传车辆照片')
  126. const pData = {
  127. plate_number: this.plate_number,
  128. order_sn: this.order_sn,
  129. image_list: _image_list.join(', ')
  130. }
  131. http.postApi(config.API_DAYHIRE_HIRE_ACTIVE, pData, (resp) => {
  132. if (resp.data.code === 200) {
  133. common.simpleToast('车辆激活成功')
  134. setTimeout(function() {
  135. me.isCustomJump = false
  136. uni.navigateTo({
  137. url: `/pages/battery/battery?plate_number=${me.plate_number}&isActivePage=true`,
  138. success: function(res) {},
  139. fail: function(res) {},
  140. complete: function(res) {}
  141. });
  142. }, 500)
  143. } else {
  144. common.simpleToast(resp.data.msg)
  145. }
  146. })
  147. }
  148. }
  149. };
  150. </script>
  151. <style>
  152. @import './activation.css';
  153. </style>