无故事王国
2023-10-31 305d164f3d912e63858e433809e1053184636873
WanPai/Root/Other/View/StoresChooseView.swift
@@ -27,7 +27,7 @@
    private var storesModel = [CityProfileModel]()
    private var clouse:((CityProfileModel,CityProfileModel,CityProfileModel)->Void)!
    private var clouse:((CityProfileModel,CityProfileModel?,CityProfileModel)->Void)!
    private let disposeBag = DisposeBag()
   private var defaultStoreModel:HomeStoreModel?
@@ -39,7 +39,7 @@
        layoutIfNeeded()
    }
    
   static func show(defaultM:HomeStoreModel? = nil, clouse:@escaping (CityProfileModel,CityProfileModel,CityProfileModel)->Void){
   static func show(defaultM:HomeStoreModel? = nil, clouse:@escaping (CityProfileModel,CityProfileModel?,CityProfileModel)->Void){
        let storesView = StoresChooseView.jq_loadNibView()
        storesView.clouse = clouse
      storesView.defaultStoreModel = defaultM
@@ -47,15 +47,23 @@
      sceneDelegate?.window?.addSubview(storesView)
      if let m = defaultM{
         storesView.label_city.text = m.city
         storesView.label_province.text = m.province
         storesView.label_currently.text = m.name
         storesView.label_city.text = m.city.isEmpty ? "选择城市":m.city
         storesView.label_province.text = m.province.isEmpty ? "选择省份":m.province
         storesView.label_currently.text = m.name.isEmpty ? "选择门店":m.name
         storesView.provinceModel = CityProfileModel(id: 0, code: m.provinceCode, name: m.province)
         storesView.cityModel = CityProfileModel(id: 0, code: m.cityCode, name: m.city)
         storesView.storeModel = CityProfileModel(id: m.storeId, code: 0, name: m.name)
         storesView.getData(m.provinceCode)
         storesView.getStore(m.cityCode)
         if m.provinceCode != 0{
            storesView.provinceModel = CityProfileModel(id: 0, code: m.provinceCode, name: m.province)
            storesView.getData(m.provinceCode)
            storesView.getStore(m.cityCode,provinceCode: m.provinceCode)
         }
         if m.cityCode != 0{
            storesView.cityModel = CityProfileModel(id: 0, code: m.cityCode, name: m.city)
         }
         if m.storeId != 0{
            storesView.storeModel = CityProfileModel(id: m.storeId, code: 0, name: m.name)
         }
      }
        UIView.animate(withDuration: 0.4) {
@@ -77,8 +85,8 @@
        }).disposed(by: disposeBag)
    }
    private func getStore(_ cityCode:Int){
        Services.queryStoreAtCity(cityCode: cityCode).subscribe(onNext: { [weak self] data in
   private func getStore(_ cityCode:Int?,provinceCode:Int){
      Services.queryStoreAtCity(cityCode: cityCode, provinceCode: provinceCode).subscribe(onNext: { [weak self] data in
            guard let weakSelf = self else { return }
            weakSelf.storesModel = data.data ?? []
        }).disposed(by: disposeBag)
@@ -109,15 +117,17 @@
        let names = provincesModel.map({$0.name})
        JQ_MenuView().show(self, tapView: sender, items: names, menuWidth: sender.jq_width, tableHei: 200) { [weak self] index, str in
            guard let weakSelf = self else { return }
            weakSelf.provinceModel = weakSelf.provincesModel[index]
            weakSelf.label_province.text = weakSelf.provinceModel?.name ?? ""
            weakSelf.getData(weakSelf.provinceModel!.code)
         weakSelf.cityModel = nil
         weakSelf.label_city.text = "选择城市"
         weakSelf.storeModel = nil
         weakSelf.label_currently.text = "选择门店"
            weakSelf.provinceModel = weakSelf.provincesModel[index]
            weakSelf.label_province.text = weakSelf.provinceModel?.name ?? ""
            weakSelf.getData(weakSelf.provinceModel!.code)
         weakSelf.getStore(weakSelf.cityModel?.code,provinceCode: weakSelf.provinceModel!.code)
        }
    }
@@ -126,11 +136,14 @@
        guard citysModel.count != 0 else {alertError(msg: "当前城市未开通");return}
        JQ_MenuView().show(self, tapView: sender, items: citysModel.map({$0.name}), menuWidth: sender.jq_width, tableHei: 200) { [weak self] index, str in
            guard let weakSelf = self else { return }
            weakSelf.cityModel = weakSelf.citysModel[index]
            weakSelf.label_city.text = weakSelf.cityModel?.name ?? ""
            weakSelf.getStore(weakSelf.cityModel!.code)
         weakSelf.storeModel = nil
         weakSelf.label_currently.text = "选择门店"
            weakSelf.cityModel = weakSelf.citysModel[index]
            weakSelf.label_city.text = weakSelf.cityModel?.name ?? ""
         weakSelf.getStore(weakSelf.cityModel?.code,provinceCode: weakSelf.provinceModel!.code)
        }
    }
@@ -140,9 +153,9 @@
            alertError(msg: "请先选择省份");return
        }
        guard cityModel != nil else {
            alertError(msg: "请先选城市");return
        }
//        guard cityModel != nil else {
//            alertError(msg: "请先选城市");return
//        }
        JQ_MenuView().show(self, tapView: sender, items: storesModel.map({$0.name}), menuWidth: sender.jq_width, tableHei: 200) { [weak self] index, str in
            guard let weakSelf = self else { return }
@@ -161,9 +174,9 @@
         alertError(msg: "请先选择省份");return
      }
      guard cityModel != nil else {
         alertError(msg: "请先选城市");return
      }
//      guard cityModel != nil else {
//         alertError(msg: "请先选城市");return
//      }
        guard storeModel != nil else {
@@ -171,7 +184,7 @@
        }
        close()
      clouse?(provinceModel!,cityModel!,storeModel!)
      clouse?(provinceModel!,cityModel,storeModel!)
    }
    
}