/**
*
* ------------ 三级联动代码区域 ------------
*/
//创建门店 picker 数据
createShops:function(){
let globalShops = [...app.globalData.companyShopList]
let branchs = [] // 分公司
let subBranchs = [] // 子分公司 和分公司下的店
let branchShops = [] // 子分公司下的店
let indexs = self.data.compShopIndex // 为了实现每次打开picker数据能保持,(没实现想要的结果)
globalShops.forEach((dic,index) => {
if (dic.supOrgCd == "ZD"){
branchs.push(dic)
}
})
globalShops.forEach(dic => {
if (dic.supOrgCd == branchs[indexs[0]].orgCd){
subBranchs.push(dic)
}
})
subBranchs.unshift({ orgCd: "-1", orgNm: "全部门店" })
globalShops.forEach(dic => {
if (dic.supOrgCd == subBranchs[indexs[1]].orgCd) {
branchShops.push(dic)
}
})
if(branchShops.length>0){
branchShops.unshift({orgCd:"-1",orgNm:"全部门店"})
}
let pickerShops = []
pickerShops[0] = branchs
pickerShops[1] = subBranchs
pickerShops[2] = branchShops
self.setData({
shops : pickerShops
})
},
// 滚动picker 创建分公司数据下的店数据
changeSubBranch:function(column,orgCd){
let globalShops = [...app.globalData.companyShopList]
let subBranchs = []
globalShops.forEach(dic => {
if (dic.supOrgCd == orgCd) {
subBranchs.push(dic)
}
})
if(column == 0){
let pickerShops = []
subBranchs.unshift({ orgCd: "-1", orgNm: "全部门店" })
globalShops.forEach(dic => {
if (dic.supOrgCd == subBranchs[0].orgCd) {
pickerShops.push(dic)
}
})
if(pickerShops.length > 0){
pickerShops.unshift({ orgCd: "-1", orgNm: "全部门店" })
}
self.data.shops[2] = pickerShops
}else{
if (subBranchs.length > 0) {
subBranchs.unshift({ orgCd: "-1", orgNm: "全部门店" })
}
}
self.data.shops[column + 1] = subBranchs
self.setData({
shops: self.data.shops
})
},
// 滚动触发
pickerChange:function(e){
let column = e.detail.column
let value = e.detail.value
if(column == 0 || column == 1){
let orgCd = self.data.shops[column][value].orgCd
self.changeSubBranch(column, orgCd)
if(column == 0){
self.data.compShopIndex[1] = 0
}
self.data.compShopIndex[2] = 0
}
self.data.compShopIndex[column] = value
self.setData({
compShopIndex: self.data.compShopIndex
})
},
// 点确定时:
selectedSure:function(e){
self.setData({
compShopIndex:e.detail.value,
comShopSureIndex:e.detail.value,
})
self.selectShopsCreate()
},
//创建搜索传参数组
selectShopsCreate:function(){
let shops = []
let compIndex = self.data.comShopSureIndex
let compShops = self.data.shops
if(compShops[2].length <= 0){ //选择在分公司下的二级维度
if(compIndex[1] == 0){ // 查全部分公司
compShops[1].forEach((dic,index) => {
if(index != 0){
if (dic.orgType == "0002"){ // 是子公司
let globalShops = app.globalData.companyShopList
globalShops.forEach(subDic => {
if (dic.orgCd == subDic.supOrgCd){
shops.push(subDic.orgCd)
}
})
}else{
shops.push(dic.orgCd)
}
}
})
}else{ // 分公司下的单个店
let dic = compShops[1][compIndex[1]]
shops.push(dic.orgCd)
}
}else{ // 在子公司下的三级维度
if(compIndex[2] == 0){// 查看全部子公司数据
compShops[2].forEach((dic,index) => {
if(index != 0){
shops.push(dic.orgCd)
}
})
}else{
let dic = compShops[2][compIndex[2]]
shops.push(dic.orgCd)
}
}
console.log(shops)
slelectShop = shops
if (self.data.currentTab == '10') {
self.getDayDate(self.data.currentTab)
} else {
self.getShopSale(self.data.currentTab);
}
},
<picker class="inputView" mode = "multiSelector" range = "{{shops}}" range-key = "orgNm" value = "{{compShopIndex}}" bindchange="selectedSure" bindcolumnchange = "pickerChange" >
<input class="selectShop" disabled="true" value="{{shops[0][comShopSureIndex[0]].orgNm}}-{{shops[1][comShopSureIndex[1]].orgNm}}-{{shops[2][comShopSureIndex[2]].orgNm||''}}" placeholder="请选择要搜索的门店"></input>
</picker>