/**
*
* ------------ 三級(jí)聯(lián)動(dòng)代碼區(qū)域 ------------
*/
//創(chuàng)建門店 picker 數(shù)據(jù)
createShops:function(){
let globalShops = [...app.globalData.companyShopList]
let branchs = [] // 分公司
let subBranchs = [] // 子分公司 和分公司下的店
let branchShops = [] // 子分公司下的店
let indexs = self.data.compShopIndex // 為了實(shí)現(xiàn)每次打開picker數(shù)據(jù)能保持,(沒實(shí)現(xiàn)想要的結(jié)果)
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
})
},
// 滾動(dòng)picker 創(chuàng)建分公司數(shù)據(jù)下的店數(shù)據(jù)
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
})
},
// 滾動(dòng)觸發(fā)
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
})
},
// 點(diǎn)確定時(shí):
selectedSure:function(e){
self.setData({
compShopIndex:e.detail.value,
comShopSureIndex:e.detail.value,
})
self.selectShopsCreate()
},
//創(chuàng)建搜索傳參數(shù)組
selectShopsCreate:function(){
let shops = []
let compIndex = self.data.comShopSureIndex
let compShops = self.data.shops
if(compShops[2].length <= 0){ //選擇在分公司下的二級(jí)維度
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{ // 分公司下的單個(gè)店
let dic = compShops[1][compIndex[1]]
shops.push(dic.orgCd)
}
}else{ // 在子公司下的三級(jí)維度
if(compIndex[2] == 0){// 查看全部子公司數(shù)據(jù)
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="請(qǐng)選擇要搜索的門店"></input>
</picker>