宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
//
//  SellCarModel.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/5/12.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import Foundation
import HandyJSON
import UserDefaultsStore
import Photos
import UIKit
 
let sellCarReqStore = UserDefaultsStore<SellCarReqModel>(uniqueIdentifier: "sellCarReqStore")!
let rentCarReqStore = UserDefaultsStore<RentCarReqModel>(uniqueIdentifier: "rentCarReqStore")!
 
/// 图片存储地区
class TempImgeSaveManager {
    private static var _sharedInstance: TempImgeSaveManager?
 
    class func getSharedInstance() -> TempImgeSaveManager {
        guard let instance = _sharedInstance else {
            _sharedInstance = TempImgeSaveManager()
            return _sharedInstance!
        }
        return instance
    }
 
    private init() {} // 私有化init方法
 
    var sell_imgs_1 = [PHAsset]()
    var sell_imgs_2 = [PHAsset]()
    var sell_video_1 = [PHAsset]()
    var sell_video_1_coverImg:UIImage?
 
    var rent_imgs_1 = [PHAsset]()
 
    //销毁单例对象
    class func destroy() {
        _sharedInstance = nil
    }
}
 
/// 售卖车辆请参数模型
struct SellCarReqModel:HandyJSON,Codable,Identifiable{
    static let idKey = \Self.id
 
    var addres:String?
    var authRemark:String?
    var brandId:Int?
    var brandName:String?
    var carColor:String?
    var carIdentificationCode:String?
    var carLicensePlate:String?
    var category:Int = 1
    var cityCode:String?
    var cityName:String?
    var contactsName:String?
    var contactsPhone:String?
    var createTime:String?
    var describe:String?
    var describeImgUrl:String?
    var displacement:String?
    var dueTimeOfCompulsoryInsurance:String?
    var expirationTimeOfAnnualInspection:String?
    var id:String?
    var imgUrl:String?
    var includingTransferFee:Int = 2
    var installationConfiguration:String?
    var level:String?
    var licensingTime:String?
    var locationOfLicensePlate:String?
    var maturityTimeOfCommercialInsurance:String?
    var mileage:Double?
    var mortgage:Int = 0
    var newCarPrice:Double?
    var operationUpdateTime:String?
    var provinceCode:String?
    var provinceName:String?
    var remainingOperationTime:String?
    var status:PublishState = .del
    var title:String?
    var transferPrice:Double?
    var transferTimes:Int?
    var transmissionCase:String?
    var userId = readUser().id
    var userType:UserAuthorType = .user
    var videoUrl:String?
 
    func save(){
        do{
            try sellCarReqStore.save(self)
        }catch{
 
        }
    }
 
    func clear(){
        sellCarReqStore.deleteAll()
    }
 
    static func get()->SellCarReqModel{
        if let m = sellCarReqStore.allObjects().first{
            return m
        }else{
            return SellCarReqModel()
        }
    }
 
    //是否被修改,初始化时,全部为nil, 在编辑或新增时,只要开始编辑,就会赋值,此时状态被更改
    var hasValue:Bool{
        get{
            if !(addres?.isEmpty ?? true) ||
               !(authRemark?.isEmpty ?? true) ||
                !(brandName?.isEmpty ?? true) ||
                !(carColor?.isEmpty ?? true) ||
                !(carIdentificationCode?.isEmpty ?? true) ||
                !(carLicensePlate?.isEmpty ?? true) ||
                !(cityCode?.isEmpty ?? true) ||
                !(cityName?.isEmpty ?? true) ||
                !(contactsName?.isEmpty ?? true) ||
                !(contactsPhone?.isEmpty ?? true) ||
                !(createTime?.isEmpty ?? true) ||
                !(describe?.isEmpty ?? true) ||
                !(describeImgUrl?.isEmpty ?? true) ||
                !(displacement?.isEmpty ?? true) ||
                !(dueTimeOfCompulsoryInsurance?.isEmpty ?? true) ||
                !(expirationTimeOfAnnualInspection?.isEmpty ?? true) ||
                !(id?.isEmpty ?? true) ||
                !(imgUrl?.isEmpty ?? true) ||
                !(installationConfiguration?.isEmpty ?? true) ||
                !(level?.isEmpty ?? true) ||
                !(licensingTime?.isEmpty ?? true) ||
                !(locationOfLicensePlate?.isEmpty ?? true) ||
                !(maturityTimeOfCommercialInsurance?.isEmpty ?? true) ||
                mileage != nil ||
                newCarPrice != nil ||
                !(operationUpdateTime?.isEmpty ?? true) ||
                !(provinceCode?.isEmpty ?? true) ||
                !(provinceName?.isEmpty ?? true) ||
                !(remainingOperationTime?.isEmpty ?? true) ||
                !(title?.isEmpty ?? true) ||
                transferPrice != nil ||
                transferTimes != nil ||
                !(transmissionCase?.isEmpty ?? true) ||
                !(videoUrl?.isEmpty ?? true) {
                return true
            }
            return false
        }
    }
 
    func checkInputValue()->Bool{
        guard title !=  nil && !(title?.isEmpty ?? true) else {
            alert(text: "请输入标题");return false
        }
 
        guard carIdentificationCode != nil && !(carIdentificationCode?.isEmpty ?? true) else {
            alert(text: "请输入车辆识别代码");return false
        }
 
        //73653 【我要卖车】 车辆识别代码不限制
//        guard carIdentificationCode!.length == 17 else {
//            alert(text: "请输入正确的车辆识别代码");return false
//        }
 
        guard carLicensePlate != nil && !(carLicensePlate?.isEmpty ?? true) else {
            alert(text: "请输入车牌号");return false
        }
 
        guard brandName != nil && !(brandName?.isEmpty ?? true) else {
            alert(text: "请选择车辆品牌");return false
        }
 
        guard carColor != nil && !(carColor?.isEmpty ?? true) else {
            alert(text: "请输入车辆颜色");return false
        }
 
        guard licensingTime != nil && !(licensingTime?.isEmpty ?? true) else {
            alert(text: "请选择首次上牌时间");return false
        }
 
        guard mileage != nil && mileage != 0 else {
            alert(text: "请输入行程里程");return false
        }
 
        guard locationOfLicensePlate != nil && !(locationOfLicensePlate?.isEmpty ?? true) else {
            alert(text: "请输入牌照所在地");return false
        }
 
        guard transferTimes != nil else {
            alert(text: "请输入过户次数");return false
        }
 
        guard displacement != nil && !(displacement?.isEmpty ?? true) else {
            alert(text: "请选择排量");return false
        }
 
        guard transmissionCase != nil  && !(transmissionCase?.isEmpty ?? true)else {
            alert(text: "请选择变速箱");return false
        }
 
        guard level != nil  && !(level?.isEmpty ?? true)else {
            alert(text: "请选择级别");return false
        }
 
        guard transferPrice != nil && transferPrice != 0 else {
            alert(text: "请输入转让价格");return false
        }
 
        guard newCarPrice != nil && newCarPrice != 0 else {
            alert(text: "请输入新车价格");return false
        }
 
        guard provinceName != nil && !(provinceName?.isEmpty ?? true) else {
            alert(text: "请选择省份");return false
        }
 
        guard cityName != nil && !(cityName?.isEmpty ?? true) else {
            alert(text: "请选择市");return false
        }
 
        guard addres != nil && !(addres?.isEmpty ?? true) else {
            alert(text: "请输入详细地址");return false
        }
 
        guard dueTimeOfCompulsoryInsurance != nil && !(dueTimeOfCompulsoryInsurance?.isEmpty ?? true) else {
            alert(text: "请选择交强险时间");return false
        }
 
        guard expirationTimeOfAnnualInspection != nil && !(expirationTimeOfAnnualInspection?.isEmpty ?? true) else {
            alert(text: "请选择年检到期时间");return false
        }
 
        guard maturityTimeOfCommercialInsurance != nil && !(maturityTimeOfCommercialInsurance?.isEmpty ?? true) else {
            alert(text: "请选择商业险到期时间");return false
        }
 
        return true
    }
}
 
struct RentCarReqModel:HandyJSON,Codable,Identifiable{
    static let idKey = \Self.id
    
    var id:String?
    var title:String?
    var addres:String?
    var authRemark:String?
    var brandId:Int = 0
    var brandName:String?
    var category:String?
    var cityCode:String?
    var cityName:String?
    var contactsPhone:String?
    var contactsName:String?
    var createTime:String?
    var deposit:Double?
    var describe:String?
    var describeImgUrl:String?
    var displacement:String?
    var gear:String?
    var imgUrl:String?
    var pickUpCarCarCertificates:String?
    var provinceCode:String?
    var provinceName:String?
    var rentMoney:Double?
    var seat:String?
    var status:PublishState = .del
    var userId = readUser().id
    var userType:UserAuthorType = .user
    var videoUrl:String?
 
    func save(){
        do{
            try rentCarReqStore.save(self)
        }catch{
 
        }
    }
 
    func clear(){
        rentCarReqStore.deleteAll()
    }
 
    static func get()->RentCarReqModel{
        if let m = rentCarReqStore.allObjects().first{
            return m
        }else{
            return RentCarReqModel()
        }
    }
 
    //是否被修改,初始化时,全部为nil, 在编辑或新增时,只要开始编辑,就会赋值,此时状态被更改
    var hasValue:Bool{
        get{
            if !(addres?.isEmpty ?? true) ||
                !(title?.isEmpty ?? true) ||
                !(category?.isEmpty ?? true) ||
                !(seat?.isEmpty ?? true) ||
                !(displacement?.isEmpty ?? true) ||
                !(gear?.isEmpty ?? true) ||
                !(pickUpCarCarCertificates?.isEmpty ?? true) ||
                (deposit != nil && deposit != 0) ||
                (rentMoney != nil && rentMoney != 0) ||
                !(brandName?.isEmpty ?? true) ||
                !(cityCode?.isEmpty ?? true) ||
                !(cityName?.isEmpty ?? true) ||
                !(contactsPhone?.isEmpty ?? true) ||
                !(describe?.isEmpty ?? true) ||
                !(provinceCode?.isEmpty ?? true) ||
                !(cityCode?.isEmpty ?? true) {
                return true
            }
            return false
        }
    }
 
    func checkInputValue()->Bool{
 
        guard title != nil else {
            alert(text: "请输入标题");return false
        }
 
        guard category != nil else {
            alert(text: "请选择类别");return false
        }
 
        guard brandName != nil else {
            alert(text: "请选择品牌");return false
        }
 
        guard seat != nil && !(seat?.isEmpty ?? true) else {
            alert(text: "请输入座位");return false
        }
 
        guard displacement != nil else {
            alert(text: "请选择排量");return false
        }
 
        guard gear != nil else {
            alert(text: "请选择档位");return false
        }
 
        guard pickUpCarCarCertificates != nil else {
            alert(text: "请选择取车证件");return false
        }
 
        guard rentMoney != 0 else {
            alert(text: "请输入租金金额");return false
        }
 
        guard deposit != 0 else {
            alert(text: "请输入押金金额");return false
        }
 
        guard provinceName != nil else {
            alert(text: "请选择省份");return false
        }
 
        guard cityName != nil else {
            alert(text: "请选择市");return false
        }
 
        guard addres != nil else {
            alert(text: "请输入详细地址");return false
        }
 
        return true
    }
 
}
 
struct BrandModel:HandyJSON {
    var id = 0
    var imgUrl = ""
    var insertTime = ""
    var name = ""
    var remark = ""
    var state = 0
}
 
struct ConfigModel:HandyJSON {
    var name = ""
    var check = false
}
 
extension ConfigModel{
    static func localConfig()->[ConfigModel]{
        var temp = Array<Self>()
        temp.append(ConfigModel(name: "GPS导航"))
        temp.append(ConfigModel(name: "倒车影像"))
        temp.append(ConfigModel(name: "前车雷达"))
        temp.append(ConfigModel(name: "全景摄像头"))
        temp.append(ConfigModel(name: "车内氛围灯"))
        temp.append(ConfigModel(name: "车载电视"))
        temp.append(ConfigModel(name: "定速巡航"))
        temp.append(ConfigModel(name: "多媒体控制"))
        temp.append(ConfigModel(name: "胎压监测"))
        temp.append(ConfigModel(name: "氙气大灯"))
        temp.append(ConfigModel(name: "铝合金轮圈"))
        temp.append(ConfigModel(name: "车载冰箱"))
        temp.append(ConfigModel(name: "行车显示屏"))
        temp.append(ConfigModel(name: "运动座椅"))
        return temp
    }
}