// 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[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 = { 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')) { // 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 }) } else if (item.imgType == '11' || item.imgType == '12') { // 2021.11.17 左侧固定 志愿团队 共建联盟 this.data.tabRightList.push(item) this.setData({ tabRightList: this.data.tabRightList.sort(compare('sort')) }) } }) resolve() }).catch(err => { console.log(err) reject() }) }) } } })