锦水志愿者去哪小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.8 KiB

// heartBehavior.js 用于更改e锦水小程序和志愿者小程序共同行为
// 数组排序 按照 sort 属性
function compare(property) {
return function (a, b) {
var value1 = a[property]
var value2 = b[property]
return value1 - value2
}
}
// 拆分数组
function group(array, subGroupLength) {
let index = 0
let newArray = []
while(index < array.length) {
newArray.push(array.slice(index, index += subGroupLength))
}
return newArray
}
var api = require("activity.js")
module.exports = Behavior ({
data: {
tabList: [],
tabRightList: [], //拼团购和顺道捎
tabLeftList: [], // 首页配置按钮+申请发单按钮
},
methods: {
// beheaviors 加载成功 基础库2.9.2
loadBehavior () {
console.log('load heartBehavior')
Promise.all([this.getModuleList(), this.getImgUrl()]).then( () => {
let newArr = group(this.data.tabList.sort(compare('sort')), 2)
this.setData({
tabLeftList: newArr[0],
tabRightList: newArr[1]
})
})
},
// 获取模块信息
getModuleList: function () {
return new Promise((resolve, reject) => {
let params = {
pageIndex: 1,
pageSize: 10,
pid: '0'
}
api.moduleCategory(params).then(res => {
console.log('获取模块列表',res.data)
res.data.forEach( item => {
if (item.categoryCode == 'shouye') {
this.data.tabList.push(item)
this.setData({
shouye: item,
tabList: this.data.tabList
})
}
})
resolve()
}).catch(err => {
console.log(err)
reject()
})
})
},
// 获取配置图片
getImgUrl:function (){
return new Promise((resolve, reject) => {
let params = {
imageTypes: '0, 5, 8, 9'
}
api.getImgUrlList(params).then(res => {
res.data.forEach( item => {
if (item.imgType == '0') {
this.setData({
getImgUrl: item
})
} else if (item.imgType == '5' && (item.imgCode == 'ptg' || item.imgCode == 'sds')) {
this.data.tabList.push(item)
this.setData({
tabList: this.data.tabList
})
} else if (item.imgType == '8') {
this.setData({
scanBtn: item
})
} else if (item.imgType == '9') {
this.data.tabList.push(item)
this.setData({
tabList: this.data.tabList
})
}
})
resolve()
}).catch(err => {
console.log(err)
reject()
})
})
}
}
})