6 changed files with 123 additions and 69 deletions
@ -0,0 +1,101 @@ |
|||
// 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() |
|||
}) |
|||
}) |
|||
} |
|||
} |
|||
}) |
Loading…
Reference in new issue