锦水居民端小程序
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.

114 lines
3.4 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( () => {
4 years ago
// let newArr = group(this.data.tabList.sort(compare('sort')), 2)
// this.setData({
// tabLeftList: newArr[1],
// tabRightList: newArr[0]
// })
// 2021.11.17 取消排序
})
},
// 获取模块信息
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 = {
4 years ago
imageTypes: '0, 5, 8, 9, 11, 12'
}
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')) {
4 years ago
// 2021.11.17 取消排序
// this.data.tabList.push(item)
// this.setData({
// tabList: this.data.tabList
// })
this.data.tabLeftList.push(item)
this.setData({
tabLeftList: this.data.tabLeftList.sort(compare('sort'))
})
} 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
applyBtn: item
})
4 years ago
} else if (item.imgType == '11' || item.imgType == '12') {
// 2021.11.17 左侧固定 志愿团队 共建联盟
this.data.tabRightList.push(item)
4 years ago
this.setData({
tabRightList: this.data.tabRightList.sort(compare('sort'))
4 years ago
})
}
})
resolve()
}).catch(err => {
console.log(err)
reject()
})
})
}
}
})