CNLiveShopClassilyViewModel.swift
4.41 KB
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
//
// CNLiveShopClassilyViewModel.swift
// metaCode
//
// Created by zx on 2023/11/18.
//
import Foundation
import CNLiveRequestBastKit
class CNLiveShopClassilyViewModel: BaseModel{
/// 添加分类接口
/// @param model 分类数据
/// @param resultBlock 请求完成回调
static func postAddCateRequestWithModel(model:CNLiveShopClassifyModel,resultBlock: @escaping downSlideResultBlock){
let param = NSMutableDictionary()
param.setValue(model.shop_id, forKey: "shop_id")
param.setValue(model.title, forKey: "title")
param.setValue(model.state, forKey: "state")
param.setValue(model.isnav, forKey: "isnav")
param.setValue(model.ord, forKey: "ord")
param.setValue(model.pid, forKey: "pid")
param.setValue(model.simg, forKey: "simg")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjBUrl+"/api/v1/addCate", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
resultBlock(result as Any,.success)
}else{
resultBlock(NSNull(),.failed)
}
}
}
/// 获取分类列表
/// @param shopId 店铺id
/// @param resultBlock 回调
static func getCateListWithShopId(shopId:String,resultBlock: @escaping downSlideResultBlock){
let param = NSMutableDictionary()
param.setValue(shopId, forKey: "shop_id")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseWjjBUrl+"/api/v1/cateList", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let res = (result as! Dictionary<String, Any>)["data"] as! Dictionary<String, Any>
let listModel = newDictionaryToModel(res, CNLiveShopClassifyListModel.self)
resultBlock(listModel as Any,.success)
}else{
resultBlock(NSNull(),.failed)
}
}
}
/// 编辑分类接口
/// @param model 分类数据
/// @param resultBlock 请求完成回调
static func postEditCateRequestWithModel(model:CNLiveShopClassifyModel,resultBlock: @escaping downSlideResultBlock){
let param = NSMutableDictionary()
param.setValue(model.shop_id, forKey: "shop_id")
param.setValue(model.title, forKey: "title")
param.setValue(model.state, forKey: "state")
param.setValue(model.isnav, forKey: "isnav")
param.setValue(model.ord, forKey: "ord")
param.setValue(model.id, forKey: "id")
param.setValue(model.simg, forKey: "simg")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjBUrl+"/api/v1/editCate", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
resultBlock(result as Any,.success)
}else{
resultBlock(NSNull(),.failed)
}
}
}
/// 删除分类接口
/// @param model 分类数据
/// @param resultBlock 请求完成回调
static func postDeleteCateRequestWithModel(model:CNLiveShopClassifyModel,resultBlock: @escaping downSlideResultBlock){
let param = NSMutableDictionary()
param.setValue(model.id, forKey: "id")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjBUrl+"/api/v1/delCate", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
resultBlock(result as Any,.success)
}else{
resultBlock(NSNull(),.failed)
}
}
}
}