detail.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="wrapper">
  3. <!-- <div class="content-box" v-if="checkState === 0 || checkState === 1">
  4. <view class="opt-view">
  5. <view >认证状态</view>
  6. <view class="check-state-0" v-if="checkState === 0">
  7. <u-tag
  8. text="认证中"
  9. shape="square"
  10. ></u-tag>
  11. </view>
  12. <view class="check-state-1" v-if="checkState === 1">
  13. <u-tag
  14. text="已认证"
  15. shape="square"
  16. ></u-tag>
  17. </view>
  18. </view>
  19. </div> -->
  20. <div class="content-box">
  21. <h4>车牌号码</h4>
  22. <view class="plate-number">
  23. <view class="plate-item" v-for="(item, index) in plateList" :key="index" :class="{'ml-10': item.ml10, current:index == currentIndex}">
  24. <!-- #ifdef MP-WEIXIN -->
  25. <u-input
  26. class="field-input"
  27. input-align="center"
  28. :border-bottom="false"
  29. v-model="item.text"
  30. :maxlength="1"
  31. @click="showKeyboard(index)"
  32. :custom-style="{backgroundColor:'#80808020',borderRadius: '10rpx', width: '80rpx', height: '100rpx'}"
  33. :style="{width: '80rpx'}"
  34. :clearable="false"
  35. placeholder=" "
  36. disabled
  37. ></u-input>
  38. <!-- #endif -->
  39. <!-- #ifndef MP-WEIXIN -->
  40. <u-input
  41. class="field-input"
  42. input-align="center"
  43. :border-bottom="false"
  44. v-model="item.text"
  45. :maxlength="1"
  46. @click="showKeyboard(index)"
  47. :custom-style="{backgroundColor:'#EFEFEFFF',borderRadius: '10rpx', width: '80rpx', height: '100rpx'}"
  48. :style="{width: '80rpx'}"
  49. :clearable="false"
  50. placeholder=" "
  51. disabled
  52. ></u-input>
  53. <!-- #endif -->
  54. </view>
  55. </view>
  56. <u-keyboard
  57. ref="uKeyboard"
  58. mode="car"
  59. v-model="isShowKeyboard"
  60. @change="valChange"
  61. @confirm="hideKeyboard"
  62. @backspace="backspace"
  63. :abc="showAbc"
  64. safe-area-inset-bottom
  65. :mask="false"
  66. ></u-keyboard>
  67. </div>
  68. <!-- 上传凭证 -->
  69. <div class="content-box">
  70. <view class="opt-view">
  71. <view class="img-title">上传行驶证,完成车辆认证</view>
  72. <view class="images-view">
  73. <u-upload
  74. :header="{ accessToken: storage.getAccessToken() }"
  75. :action="action"
  76. width="150"
  77. @on-remove="onRemove"
  78. @on-success="onSuccess"
  79. @on-error="onError"
  80. :before-upload="beforeUpload"
  81. :max-count="1"
  82. :fileList="fileList"
  83. :show-progress="false"
  84. :deletable="canEdit"
  85. ></u-upload>
  86. </view>
  87. <view class="img-tip" v-if="canEdit">请上传车辆行驶证主页(带红印)</view>
  88. </view>
  89. </div>
  90. <u-button type="success" :ripple="true" shape="circle" @click="save" v-if="canEdit" :loading="loading">提交</u-button>
  91. <u-top-tips ref="uTips"></u-top-tips>
  92. </div>
  93. </template>
  94. <script>
  95. import storage from "@/utils/storage.js";
  96. import config from "@/config/config";
  97. import { addCar, getCar, updateCar } from "@/api/car.js";
  98. import { upload } from "@/api/common.js";
  99. export default {
  100. data() {
  101. return {
  102. storage,
  103. config,
  104. fileList: [],
  105. action: upload, //图片上传地址
  106. img: [],
  107. isShowKeyboard: true,
  108. plateList: [
  109. {},
  110. {},
  111. { ml10: true },
  112. {},
  113. {},
  114. {},
  115. {},
  116. {},
  117. ],
  118. currentIndex: 0,
  119. showAbc: false,
  120. canEdit: true,
  121. carId: undefined,
  122. checkState: -1,
  123. loading: false
  124. };
  125. },
  126. watch: {
  127. },
  128. onLoad(options) {
  129. this.carId = options.id
  130. this.loadCarInfo()
  131. },
  132. methods: {
  133. async loadCarInfo(){
  134. if(this.carId == null) return
  135. const res = await getCar(this.carId)
  136. const data = res.data.data;
  137. this.checkState = data.checkState
  138. this.canEdit = (this.checkState === 2 || this.checkState === 3)
  139. this.isShowKeyboard = this.canEdit
  140. const title = this.canEdit ? "编辑车辆" : "车辆详情"
  141. uni.setNavigationBarTitle({
  142. title: title
  143. });
  144. for(let index = 0; index < this.plateList.length; index++){
  145. this.plateList[index].text = data.plateNo[index]
  146. }
  147. if(data.licenseImgs && data.licenseImgs.length > 0){
  148. this.img = JSON.parse(data.licenseImgs)
  149. }
  150. data.licenseImgsShow.forEach((item) => {
  151. this.fileList.push({url: item})
  152. });
  153. },
  154. //图片上传成功
  155. onSuccess(data, index, lists, name) {
  156. this.img.push(data.data.name);
  157. this.loading = false
  158. },
  159. //删除图片
  160. onRemove(index, lists, name) {
  161. this.img.splice(index, 1);
  162. },
  163. onError(res, index, lists, name) {
  164. this.loading = false
  165. },
  166. beforeUpload(index, list) {
  167. this.loading = true
  168. return true;
  169. },
  170. /**
  171. * 提交车辆审核
  172. */
  173. async save() {
  174. let params = {}
  175. params.plateNo = "";
  176. this.plateList.forEach((platItem, index) => {
  177. const text = platItem.text;
  178. if (text != null && text !== '') {
  179. params.plateNo += text
  180. }
  181. })
  182. if (!this.$u.test.carNo(params.plateNo)) {
  183. uni.showToast({
  184. title: "请填入正确的车牌号码",
  185. duration: 2000,
  186. icon: "none",
  187. });
  188. return false;
  189. }
  190. /** 提交 */
  191. params.licenseImgs = JSON.stringify(this.img)
  192. let submitMethod = addCar;
  193. if(this.carId != null){
  194. params.id = this.carId
  195. submitMethod = updateCar
  196. }
  197. const res = await submitMethod(params)
  198. if (res.data.code == 200) {
  199. uni.showToast({
  200. title: "提交成功!",
  201. duration: 2000,
  202. icon: "success",
  203. });
  204. setTimeout(() => {
  205. uni.navigateBack({
  206. delta: 1,
  207. });
  208. }, 1000);
  209. } else if (res.data.msg != null) {
  210. this.$refs.uTips.show({ title: res.data.msg, type: "error" });
  211. }
  212. },
  213. showKeyboard(index) {
  214. // uni.hideKeyboard();
  215. if(this.canEdit === false) return
  216. this.currentIndex = index;
  217. this.showAbc = this.currentIndex == 0 ? false : true
  218. this.isShowKeyboard = true
  219. },
  220. hideKeyboard() {
  221. this.isShowKeyboard = false
  222. },
  223. // 按键被点击(点击退格键不会触发此事件)
  224. valChange(val) {
  225. // 将每次按键的值拼接到value变量中,注意+=写法
  226. this.plateList[this.currentIndex].text = val;
  227. this.currentIndex++;
  228. if (this.currentIndex >= this.plateList.length) {
  229. this.currentIndex = 0;
  230. this.isShowKeyboard = false
  231. }
  232. this.showAbc = this.currentIndex == 0 ? false : true
  233. },
  234. // 退格键被点击
  235. backspace() {
  236. for (let index = this.currentIndex; index >= 0; index--) {
  237. let text = this.plateList[index].text;
  238. console.log(text === null)
  239. console.log(text === '')
  240. if (text !== null && text !== '') {
  241. this.plateList[index].text = ''
  242. this.$set(this.plateList, index, this.plateList[index])
  243. this.currentIndex = index;
  244. if (this.currentIndex <= 0) {
  245. this.currentIndex = 0;
  246. this.isShowKeyboard = false
  247. }
  248. break;
  249. }
  250. }
  251. this.showAbc = this.currentIndex == 0 ? false : true
  252. }
  253. },
  254. };
  255. </script>
  256. <style lang="scss" scoped>
  257. .wrapper {
  258. padding: 30rpx;
  259. }
  260. .content-box {
  261. position: relative;
  262. padding: 30rpx 0;
  263. }
  264. .check-state-0{
  265. /deep/ .u-tag {
  266. color: #FFD75C;
  267. background-color: #FFD75C16;
  268. border-color: transparent;
  269. margin-right:10rpx;
  270. margin-top:10rpx;
  271. display:inline-block;
  272. }
  273. }
  274. .check-state-1{
  275. /deep/ .u-tag {
  276. color: #46D290;
  277. background-color: #46D29016;
  278. border-color: transparent;
  279. margin-right:10rpx;
  280. margin-top:10rpx;
  281. display:inline-block;
  282. }
  283. }
  284. .word-limit {
  285. position: absolute;
  286. color: #95989e;
  287. // background-color: ;
  288. right: 48rpx;
  289. bottom: 30rpx;
  290. }
  291. /deep/ .u-input__textarea {
  292. padding: 20rpx;
  293. }
  294. /deep/ .u-input__input {
  295. padding: 0 10rpx;
  296. }
  297. h4 {
  298. font-size: 30rpx;
  299. margin-bottom: 20rpx;
  300. }
  301. .field-input {
  302. margin: 10rpx 0;
  303. border-radius: 10rpx;
  304. }
  305. .img-tip {
  306. font-size: 24rpx;
  307. color: #bdbfc0;
  308. margin-top: 10rpx;
  309. }
  310. .plate-number {
  311. display: flex;
  312. flex-direction: row;
  313. justify-content: flex-start;
  314. }
  315. .plate-item {
  316. margin: 0rpx 7rpx;
  317. width: 75rpx;
  318. }
  319. .ml-10 {
  320. margin: 0rpx 5rpx 0rpx 15rpx;
  321. }
  322. .current {
  323. border: 1px solid #0974C5;
  324. border-radius: 10rpx;
  325. }
  326. </style>