add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view>
  3. <view class="form">
  4. <view class="flex">
  5. <image style="width: 35rpx;height: 35rpx;display: block;padding-top: 6rpx;padding-right: 10rpx;" src="/static/myCar/tag1.png" mode=""></image>
  6. <text class="text-lg text-bold">请选择基本信息</text>
  7. </view>
  8. <view class="card">
  9. <u-form :model="model" ref="uForm" >
  10. <u-form-item :required="true" :label-width="labelWidth" label="车牌号码" >
  11. <u-input type="text" v-model="model.number" disabled @click="openKeyBoard" placeholder="请填写车牌号码" ></u-input>
  12. </u-form-item>
  13. <u-form-item :required="true" :label-width="labelWidth" label="车辆类型" >
  14. <u-input type="select" :select-open="carTypeShow" v-model="carTypeLabel" placeholder="请选择车辆类型" @click="carTypeShow=true"></u-input>
  15. </u-form-item>
  16. <u-form-item :required="true" :label-width="labelWidth" label="车辆性质" >
  17. <u-input type="select" :select-open="carPropertiesShow" v-model="carPropertiesLabel" placeholder="请选择车辆性质" @click="carPropertiesShow=true"></u-input>
  18. </u-form-item>
  19. <u-form-item :required="true" :label-width="labelWidth" label="燃油类别" >
  20. <u-input type="select" :select-open="fuelCategoryShow" v-model="fuelCategoryLabel" placeholder="请选择燃油类别" @click="fuelCategoryShow=true"></u-input>
  21. </u-form-item>
  22. </u-form>
  23. </view>
  24. </view>
  25. <view class="form">
  26. <view class="flex">
  27. <image style="width: 35rpx;height: 35rpx;display: block;padding-top: 6rpx;padding-right: 10rpx;" src="/static/myCar/tag1.png" mode=""></image>
  28. <text class="text-lg text-bold">请上传车辆照片</text>
  29. </view>
  30. <view class="card">
  31. <view style="padding: 20rpx 0;" @click="chooseImage(1)" class="flex justify-center ">
  32. <view class=" ">
  33. <upload-img
  34. :width="width"
  35. :height="height"
  36. :currentImage="model.carImg"
  37. bgsrc="/static/myCar/upload.png"
  38. >
  39. </upload-img>
  40. <view class="text-center padding-top-20 base-color" >
  41. <text class="cuIcon-camera padding-right-sm" style="font-size: 30rpx;"></text>
  42. <text v-if="$isEmpty(model.carImg)">点击上传车辆照片</text>
  43. <text style="margin-top: 40rpx;display: inline-block;" v-else>点击重新上传</text>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="form">
  50. <view class="flex">
  51. <image style="width: 35rpx;height: 35rpx;display: block;padding-top: 6rpx;padding-right: 10rpx;" src="/static/myCar/tag1.png" mode=""></image>
  52. <text class="text-lg text-bold">请上传行驶证正面</text>
  53. </view>
  54. <view class="card">
  55. <view style="padding: 20rpx 0;" @click="chooseImage(2)" class="flex justify-center ">
  56. <view class=" ">
  57. <upload-img
  58. :width="width"
  59. :height="height"
  60. :currentImage="model.vehicleDrivingLicense1"
  61. bgsrc="/static/myCar/zm.png"
  62. >
  63. </upload-img>
  64. <view class="text-center padding-top-20 base-color" >
  65. <text class="cuIcon-camera padding-right-sm" style="font-size: 30rpx;"></text>
  66. <text v-if="$isEmpty(model.carImg)">点击上传行驶证正面</text>
  67. <text style="margin-top: 40rpx;display: inline-block;" v-else>点击重新上传</text>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="form">
  74. <view class="flex">
  75. <image style="width: 35rpx;height: 35rpx;display: block;padding-top: 6rpx;padding-right: 10rpx;" src="/static/myCar/tag1.png" mode=""></image>
  76. <text class="text-lg text-bold">请上传行驶证反面</text>
  77. </view>
  78. <view class="card">
  79. <view style="padding: 20rpx 0;" @click="chooseImage(3)" class="flex justify-center ">
  80. <view class=" ">
  81. <upload-img
  82. :width="width"
  83. :height="height"
  84. :currentImage="model.vehicleDrivingLicense2"
  85. bgsrc="/static/myCar/fm.png"
  86. >
  87. </upload-img>
  88. <view class="text-center padding-top-20 base-color" >
  89. <text class="cuIcon-camera padding-right-sm" style="font-size: 30rpx;"></text>
  90. <text v-if="$isEmpty(model.carImg)">点击上传行驶证反面</text>
  91. <text style="margin-top: 40rpx;display: inline-block;" v-else>点击重新上传</text>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. <view >
  98. <view class="bg-white" style="height: 80rpx;"></view>
  99. <view class="" @click="submit" style="width: 90%;margin: 0 auto ;margin-bottom: 10%;">
  100. <view class="cu-btn round base-bg-color" style="padding: 40rpx;width: 100%;" >
  101. <text class="cuIcon-add"></text>
  102. <text v-text="model.id?'重新审核':'确认添加'"></text>
  103. </view>
  104. </view>
  105. </view>
  106. <u-select @confirm="carTypeConfirm" v-model="carTypeShow" :list="carTypeList"></u-select>
  107. <u-select @confirm="carPropertiesConfirm" v-model="carPropertiesShow" :list="carPropertiesList"></u-select>
  108. <u-select @confirm="fuelCategoryConfirm" v-model="fuelCategoryShow" :list="fuelCategoryList"></u-select>
  109. <keyboard-package z-index="999" ref="plateNumber" type="plateNumber" @onInput="onInput" @onDelete="onDelete" @onConfirm="onConfirm"/>
  110. </view>
  111. </template>
  112. <script>
  113. import keyboardPackage from "@/comps/keyboard-package/keyboard-package.vue"
  114. import uploadImg from '@/comps/uploadimg/uploadImg.vue'
  115. var that;
  116. var app = getApp();
  117. export default {
  118. components: {
  119. uploadImg, keyboardPackage
  120. },
  121. data() {
  122. return {
  123. labelWidth:'200',
  124. width:480,
  125. height:320,
  126. //车牌号
  127. carNoInputList:[],
  128. //车辆类型
  129. carTypeList:[],
  130. carTypeShow:false,
  131. carTypeLabel:'',
  132. //车辆性质
  133. carPropertiesList:[],
  134. carPropertiesShow:false,
  135. carPropertiesLabel:'',
  136. //燃油类别
  137. fuelCategoryList:[],
  138. fuelCategoryShow:false,
  139. fuelCategoryLabel:'',
  140. model:{
  141. type:'',//车辆类型的key
  142. number:'',//车牌号
  143. properties:'',//车辆性质的key,
  144. fuelCategory:'',//燃油类别的key
  145. carImg:'',//车辆照片
  146. vehicleDrivingLicense1:'',//行驶证正面
  147. vehicleDrivingLicense2:'',//行驶证反面
  148. personId:'',
  149. residentialId:'',
  150. },
  151. }
  152. },
  153. onLoad(options) {
  154. that = this;
  155. this.model.residentialId = uni.getStorageSync('residentialId')
  156. this.model.personId = app.globalData.userId;
  157. //获取字典
  158. this.getDict()
  159. this.parseParams(options)
  160. },
  161. computed: {
  162. plateNumberStr() {
  163. let str = '';
  164. this.carNoInputList.forEach(item=>{
  165. str += item.toString();
  166. })
  167. this.model.number=str
  168. return str;
  169. }
  170. },
  171. methods: {
  172. parseParams(options){
  173. if (this.$isEmpty(options)) {
  174. return
  175. }
  176. this.model=options
  177. this.carNoInputList=options.number.split('')
  178. this.carTypeList.forEach(item=>{
  179. if (item.value==options.type) {
  180. this.carTypeLabel=item.label
  181. }
  182. })
  183. this.carPropertiesList.forEach(item=>{
  184. if (item.value==options.properties) {
  185. this.carPropertiesLabel=item.label
  186. }
  187. })
  188. this.fuelCategoryList.forEach(item=>{
  189. if (item.value==options.fuelCategory) {
  190. this.fuelCategoryLabel=item.label
  191. }
  192. })
  193. },
  194. submit(){
  195. if (this.$isEmpty(this.model.number)) {
  196. this.$u.toast('请填写车牌号')
  197. return
  198. }
  199. if (this.$isEmpty(this.model.type)) {
  200. this.$u.toast('请选择车辆类型')
  201. return
  202. }
  203. if (this.$isEmpty(this.model.properties)) {
  204. this.$u.toast('请选择车辆性质')
  205. return
  206. }
  207. if (this.$isEmpty(this.model.fuelCategory)) {
  208. this.$u.toast('请选择燃油类型')
  209. return
  210. }
  211. if (this.$isEmpty(this.model.carImg)) {
  212. this.$u.toast('请上传车辆照片')
  213. return
  214. }
  215. if (this.$isEmpty(this.model.vehicleDrivingLicense1)) {
  216. this.$u.toast('请上传行驶证正面')
  217. return
  218. }
  219. if (this.$isEmpty(this.model.vehicleDrivingLicense2)) {
  220. this.$u.toast('请上传行驶证反面')
  221. return
  222. }
  223. let that = this;
  224. let operation = 'car/saveOrUpdate';
  225. app.globalData.postRequest(this.model, operation, function (res) {
  226. console.log(res);
  227. if (res.data.result) {
  228. that.$util.showModal('操作成功!',false).then(res=>{
  229. that.$util.isReloadAndBack()
  230. })
  231. } else {
  232. that.$util.showModal("提交失败",false);
  233. }
  234. })
  235. },
  236. getDict() {
  237. let carType = uni.getStorageSync("carType");
  238. let carProperty = uni.getStorageSync("carProperty");
  239. let fuelCategory = uni.getStorageSync("fuelCategory");
  240. if (carType && carProperty && fuelCategory) {
  241. this.carTypeList = carType;
  242. this.carPropertiesList = carProperty;
  243. this.fuelCategoryList = fuelCategory;
  244. return;
  245. }
  246. let operation = 'permissions/dict/getByCode?code=car_type';
  247. let that = this;
  248. let params = {};
  249. //车辆类型
  250. app.globalData.postRequest(params, operation, function (res) {
  251. if (res.data.code != 200) {
  252. app.globalData.oneFailHint(res.data.msg, function () {
  253. uni.switchTab({
  254. url:"../index/index"
  255. })
  256. });
  257. }
  258. res.data.list.forEach((item) => {
  259. let tmp = {
  260. value: item.dictKey,
  261. label: item.dictValue
  262. }
  263. that.carTypeList.push(tmp)
  264. })
  265. });
  266. //车辆性质
  267. operation = "permissions/dict/getByCode?code=car_properties"
  268. app.globalData.postRequest(params, operation, function (res) {
  269. if (res.data.code != 200) {
  270. app.globalData.oneFailHint(res.data.msg, function () {
  271. uni.switchTab({
  272. url:"../index/index"
  273. })
  274. });
  275. }
  276. res.data.list.forEach((item) => {
  277. let tmp = {
  278. value:item.dictKey,
  279. label:item.dictValue
  280. }
  281. that.carPropertiesList.push(tmp)
  282. })
  283. });
  284. //燃油类别
  285. operation = "permissions/dict/getByCode?code=fuel_category"
  286. app.globalData.postRequest(params, operation, function (res) {
  287. if (res.data.code != 200) {
  288. app.globalData.oneFailHint(res.data.msg, function () {
  289. uni.switchTab({
  290. url:"../index/index"
  291. })
  292. });
  293. }
  294. res.data.list.forEach((item)=>{
  295. let tmp = {
  296. value:item.dictKey,
  297. label:item.dictValue
  298. }
  299. that.fuelCategoryList.push(tmp);
  300. })
  301. });
  302. },
  303. carTypeConfirm(e){
  304. this.model.type=e[0].value
  305. this.carTypeLabel=e[0].label
  306. },
  307. carPropertiesConfirm(e){
  308. this.model.properties=e[0].value
  309. this.carPropertiesLabel=e[0].label
  310. },
  311. fuelCategoryConfirm(e){
  312. this.model.fuelCategory=e[0].value
  313. this.fuelCategoryLabel=e[0].label
  314. },
  315. //上传图片
  316. chooseImage(type) {
  317. uni.chooseImage({
  318. count: 1,
  319. //最多可以选择的图片张数,默认9
  320. sourceType: ['album'],
  321. sizeType: ['compressed'],
  322. //可选择原图或压缩后的图片
  323. success: res => {
  324. this.uploadImage(res.tempFilePaths[0], type);
  325. }
  326. });
  327. },
  328. /**上传图片
  329. * @param {Object} imgUrl 图片url
  330. */
  331. uploadImage(imgUrl, type) {
  332. var that = this;
  333. //是否需要md5加密上传人脸照
  334. let is_need_md5 = false;
  335. uni.getFileSystemManager().readFile({
  336. filePath: imgUrl,
  337. //选择图片返回的相对路径
  338. encoding: 'base64',
  339. //编码格式
  340. success: res => {
  341. //成功的回调
  342. app.globalData.uploadBase64('data:image/jpeg;base64,' + res.data, is_need_md5, function (result) {
  343. if (type == 1) {
  344. that.model.carImg = result.data.showUri;
  345. } else if (type == 2) {
  346. that.model.vehicleDrivingLicense1 = result.data.showUri;
  347. } else if (type == 3) {
  348. that.model.vehicleDrivingLicense2 = result.data.showUri;
  349. }
  350. });
  351. }
  352. });
  353. },
  354. //车牌号键盘
  355. onInput(val){
  356. this.carNoInputList.push(val)
  357. },
  358. onDelete(){
  359. this.carNoInputList.pop();
  360. },
  361. onConfirm(){
  362. this.model.number=this.plateNumberStr
  363. },
  364. openKeyBoard() {
  365. this.$refs.plateNumber.open();
  366. },
  367. }
  368. }
  369. </script>
  370. <style>
  371. page{
  372. background-color: #FFFFFF;
  373. }
  374. </style>
  375. <style lang="scss" scoped>
  376. .form {
  377. padding: 40rpx 30rpx;
  378. .card {
  379. margin-top: 20rpx;
  380. padding: 0 30rpx;
  381. box-sizing: border-box;
  382. border-radius: 12rpx;
  383. box-shadow: 0 -10rpx rgba(248, 248, 248,.9) ,0 10rpx rgba(248, 248, 248,.9) , -10rpx 0rpx rgba(248, 248, 248,.9) ,10rpx 0rpx rgba(248, 248, 248,.9);
  384. .item {
  385. padding:30rpx 0;
  386. display: flex;
  387. justify-content: space-between;
  388. }
  389. }
  390. }
  391. </style>