// const app = getApp<IAppOption>();
|
Component({
|
/**
|
* 组件的属性列表
|
*/
|
options: {
|
addGlobalClass: true,
|
multipleSlots: true // 在组件定义时的选项中启用多slot支持
|
},
|
properties: {
|
sellerList:{
|
type: Array,
|
value: []
|
},
|
from:{
|
type:String,
|
value: ''
|
}
|
// validatorInstance:{
|
// type:Object,
|
// observer: function (newVal, oldVal, changedPath) {
|
// // 属性被改变时执行的函数(可选),也可以写成在methods段中定义的方法名字符串
|
// // 通常 newVal 就是新设置的数据, oldVal 是旧数据
|
//
|
// console.log(newVal,oldVal,changedPath);
|
// }
|
// }
|
},
|
|
/**
|
* 组件的初始数据
|
*/
|
data: {
|
selectedSellerList:[
|
// {DocItem: 10, SellerId: 1, SellerName: "好几十", Telephone: "15555555555", isDefaultSellerName: false},
|
// {DocItem: 10, SellerId: 2, SellerName: "好", Telephone: "15588555555", isDefaultSellerName: false},
|
// {DocItem: 10, SellerId: 3, SellerName: "555", Telephone: "18888555555", isDefaultSellerName: false},
|
] as any,
|
selectedSeller:'',
|
selectedSellerIdList:[] as any,
|
index: -1,
|
isFirstOpen:true
|
},
|
|
lifetimes:{
|
async ready() {
|
console.log('seller edit ...ready, from:',this.data.from);
|
if (this.data.from != 'edit'){
|
await this.getDefaultSeller();
|
}
|
}
|
},
|
pageLifetimes:{
|
show(){
|
let {selectedSellerIdList,selectedSeller,isFirstOpen} = this.data;
|
console.log('isFirstOpen',isFirstOpen);
|
if (isFirstOpen) return;
|
let newSelectedSellerList = [] as any;
|
console.log('>>>>>>>>>>>>>>组件页面show开始>>>>>>>>>>>>>>');
|
console.log('页面show时 新建活动页当前的selectedSellerIdList',selectedSellerIdList);
|
if (selectedSellerIdList.length>0){
|
let selectedSellerList = this.getSelectedSellerList();
|
console.log('页面show时 新建活动页当前的selectedSellerList',selectedSellerList);
|
|
if (selectedSellerIdList.length != selectedSellerList.length) {
|
selectedSellerIdList.forEach((idItem:any)=>{
|
selectedSellerList.forEach((item:any)=>{
|
if (item.sellerId == idItem) {
|
newSelectedSellerList.push(item)
|
}
|
})
|
})
|
selectedSellerList = newSelectedSellerList;
|
|
console.log('营销人员被删除,selectedSellerList数据更新后',newSelectedSellerList);
|
this.setData({
|
selectedSellerList
|
})
|
}
|
console.log('selectedSellerIdList是否包含selectedSeller',selectedSellerIdList.includes(selectedSeller.toString() as never),selectedSellerIdList,selectedSeller.toString());
|
if (!selectedSellerIdList.includes(selectedSeller.toString() as never)) {
|
this.setData({
|
selectedSeller: selectedSellerList[0].sellerId,
|
index: 0
|
})
|
|
}
|
console.log('页面show时 新建活动页当前的selectedSeller',this.data.selectedSeller,this.data.index);
|
}
|
console.log('<<<<<<<<<<<<<<<组件页面show结束<<<<<<<<<<<<<<<');
|
}
|
},
|
observers: {
|
'sellerList': function(val) {
|
console.log('监听sellers',val,this.data.sellerList)
|
if (val.length > 0) {
|
let selectedSellerList = val;
|
let selectedSellerIdList = [] as any;
|
console.log('营销人员列表sellers。。。与id、、、',selectedSellerList,selectedSellerIdList);
|
selectedSellerList.forEach((item:any,index:number)=>{
|
selectedSellerIdList.push(item&&item.sellerId&&item.sellerId.toString());
|
if (item.isDefaultSellerName){
|
this.setData({
|
selectedSeller: item.sellerId,
|
index
|
})
|
}
|
})
|
this.setData({selectedSellerList,selectedSellerIdList});
|
}
|
|
}
|
},
|
/**
|
* 组件的方法列表
|
*/
|
methods: {
|
|
getSelectedSellerList(){
|
let {selectedSellerIdList} = this.data;
|
let selectedSellerList = [] as any;
|
let sellerList = wx.globalData.sellerList;
|
selectedSellerIdList.forEach((id:any)=>{
|
sellerList.forEach((item:any)=>{
|
if (item.sellerId == Number(id)) {
|
selectedSellerList.push(item)
|
}
|
})
|
})
|
this.setData({
|
selectedSellerList
|
})
|
return selectedSellerList;
|
},
|
|
// 父组件获取待提交的营销人员数据
|
getSellerList(){
|
let { selectedSellerList, index} = this.data;
|
selectedSellerList.forEach((item:any)=>{
|
item.isDefaultSellerName = false;
|
})
|
if (index >=0&&selectedSellerList.length>0){
|
selectedSellerList[index].isDefaultSellerName = true;
|
}
|
console.log('待提交的营销人员数据',selectedSellerList);
|
return selectedSellerList;
|
},
|
checkDefaultSeller(){
|
let { selectedSellerList } = this.data;
|
return !(selectedSellerList.every((currentValue:any)=>{
|
return currentValue.isDefaultSellerName == false;
|
}))
|
},
|
addSeller(){
|
wx.navigateTo({
|
url: `/pages/sellerList/sellerList`,
|
success: (res)=> {
|
let selectedSellerIdList = this.data.selectedSellerIdList;
|
console.log('新建活动页当前的selectedSellerIdList',selectedSellerIdList);
|
this.setData({
|
isFirstOpen:false
|
})
|
// 通过eventChannel向被打开页面传送数据
|
res.eventChannel.emit('getSellerListFromPromotionsPage', {
|
selectedSellerIdList
|
})
|
},
|
events: {
|
// 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
|
getSelectedSellerList: (data: any)=> {
|
console.log('获取营销人员选择页选中的data',data)
|
this.setData({
|
selectedSellerIdList:data.selectedSellerIdList,
|
// selectedSellerList:data.selectedSellerList
|
})
|
},
|
}
|
})
|
},
|
async getDefaultSeller(){
|
let [error, result] = await wx.$utils.to(
|
wx.$http.request({
|
url:`/shopping/panicBuyingSeller.do?m=getDefaultSeller`,
|
})
|
)
|
if (error){
|
console.log(error);
|
return;
|
}
|
console.log(result);
|
if (result.sellerList.length>0){
|
this.setData({
|
sellerList:result.sellerList
|
})
|
}
|
}
|
}
|
})
|