|
@@ -4,6 +4,7 @@ var vm = new Vue({
|
|
|
data: {
|
|
|
batchDeleteState: false, // 是否在批量删除状态
|
|
|
userData: {}, // getUserInfo接口用户原始数据
|
|
|
+ keywordsGroupList: [],
|
|
|
groupNameList: [],
|
|
|
listState: {
|
|
|
loaded: false
|
|
@@ -16,6 +17,11 @@ var vm = new Vue({
|
|
|
},
|
|
|
},
|
|
|
computed: {
|
|
|
+ groupNameListSorted: function () {
|
|
|
+ return this.groupNameList.sort(function (a, b) {
|
|
|
+ return b.updatetime - a.updatetime
|
|
|
+ })
|
|
|
+ },
|
|
|
listShow: function () {
|
|
|
return this.groupNameList.length !== 0 && this.listState.loaded
|
|
|
},
|
|
@@ -85,10 +91,10 @@ var vm = new Vue({
|
|
|
_this.userData = res.userData
|
|
|
if (res.userData && res.userData.o_vipjy) {
|
|
|
// 整理数据
|
|
|
- var list = _this.getGroupNameList(res.userData.o_vipjy.a_items)
|
|
|
- if (Array.isArray(list)) {
|
|
|
- _this.groupNameList = list
|
|
|
- }
|
|
|
+ var groupList = _this.addInfoToKeyItem(res.userData.o_vipjy.a_items)
|
|
|
+ var groupNameList = _this.getGroupNameList(groupList)
|
|
|
+ _this.keywordsGroupList = groupList
|
|
|
+ _this.groupNameList = groupNameList
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -102,20 +108,59 @@ var vm = new Vue({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ // 向关键词中添加一些信息
|
|
|
+ addInfoToKeyItem: function (groupList) {
|
|
|
+ var _this = this
|
|
|
+ if (!Array.isArray(groupList)) return []
|
|
|
+ var arr = []
|
|
|
+
|
|
|
+ groupList.forEach(function (keywordsList, index) {
|
|
|
+ if (keywordsList && Array.isArray(keywordsList.a_key)) {
|
|
|
+ keywordsList.groupIndex = index
|
|
|
+ keywordsList.updatetime = _this.getMaxUpdateTime(keywordsList.a_key)
|
|
|
+ keywordsList.a_key.forEach(function (keyword, iindex) {
|
|
|
+ // 添加一些其他信息
|
|
|
+ keyword.groupName = keywordsList.s_item // 分类名
|
|
|
+ keyword.groupIndex = index // 该关键词所在分类 在分类列表中的索引
|
|
|
+ keyword.keyIndex = iindex // 该关键词在其所在分类中的索引
|
|
|
+ if (!keyword.updatetime) {
|
|
|
+ keyword.updatetime = 0
|
|
|
+ }
|
|
|
+ })
|
|
|
+ arr.push(keywordsList)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ return arr
|
|
|
+ },
|
|
|
getGroupNameList: function (keywordsGroupList) {
|
|
|
if (!Array.isArray(keywordsGroupList)) return
|
|
|
var groupNameList = []
|
|
|
- keywordsGroupList.forEach(function (item, index) {
|
|
|
- var count = Array.isArray(item.a_key) ? item.a_key.length : 0
|
|
|
- groupNameList.push({
|
|
|
- name: item.s_item, // 分类名
|
|
|
- checked: false,
|
|
|
- deleteDisabled: count > 0, // 该分类是否能被删除
|
|
|
- count: count // 分类下有多少个关键词
|
|
|
- })
|
|
|
+ keywordsGroupList.forEach(function (item) {
|
|
|
+ if (item) {
|
|
|
+ var count = Array.isArray(item.a_key) ? item.a_key.length : 0
|
|
|
+ groupNameList.push({
|
|
|
+ name: item.s_item, // 分类名
|
|
|
+ checked: false,
|
|
|
+ deleteDisabled: count > 0, // 该分类是否能被删除
|
|
|
+ count: count, // 分类下有多少个关键词
|
|
|
+ groupIndex: item.groupIndex,
|
|
|
+ updatetime: item.updatetime
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
return groupNameList
|
|
|
},
|
|
|
+ getMaxUpdateTime: function (arr) {
|
|
|
+ var max = 0
|
|
|
+ if (!Array.isArray(arr)) return max
|
|
|
+ arr.some(function (item) {
|
|
|
+ if (item.updatetime && item.updatetime > max) {
|
|
|
+ max = item.updatetime
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return max
|
|
|
+ },
|
|
|
// 通过已有分类得到一个未分类名
|
|
|
getNewClassName: function () {
|
|
|
var conf = {
|
|
@@ -162,9 +207,9 @@ var vm = new Vue({
|
|
|
},
|
|
|
getSelectIndexArr: function () {
|
|
|
var selectedIndexArr = []
|
|
|
- this.groupNameList.forEach(function (item, index) {
|
|
|
+ this.groupNameList.forEach(function (item) {
|
|
|
if (!item.deleteDisabled && item.checked) {
|
|
|
- selectedIndexArr.push(index)
|
|
|
+ selectedIndexArr.push(item.groupIndex)
|
|
|
}
|
|
|
})
|
|
|
return selectedIndexArr
|
|
@@ -214,7 +259,7 @@ var vm = new Vue({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- clickKeyCard: function (item, index) {
|
|
|
+ clickKeyCard: function (item) {
|
|
|
if (this.batchDeleteState) {
|
|
|
// 执行点击选中逻辑
|
|
|
// 如果关键词组下有关键词,则不能点击
|
|
@@ -223,7 +268,7 @@ var vm = new Vue({
|
|
|
}
|
|
|
} else {
|
|
|
// 显示修改关键词组名弹框
|
|
|
- this.editGroupName('edit', item, index)
|
|
|
+ this.editGroupName('edit', item, item.groupIndex)
|
|
|
}
|
|
|
},
|
|
|
beforeKeySwipeCellClose: function (e) {
|
|
@@ -231,7 +276,7 @@ var vm = new Vue({
|
|
|
// instance 为对应的 SwipeCell 实例
|
|
|
var position = e.position
|
|
|
var instance = e.instance
|
|
|
- var index = e.name
|
|
|
+ var index = e.name // item.groupIndex
|
|
|
|
|
|
switch (position) {
|
|
|
case 'left': {
|
|
@@ -254,6 +299,19 @@ var vm = new Vue({
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ getGroupFromIndex: function (idx) {
|
|
|
+ var groupItem = {}
|
|
|
+ this.groupNameList.some(function (item) {
|
|
|
+ if (item) {
|
|
|
+ var gotThis = item.groupIndex == idx
|
|
|
+ if (gotThis) {
|
|
|
+ groupItem = item
|
|
|
+ }
|
|
|
+ return gotThis
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return groupItem
|
|
|
+ },
|
|
|
/**
|
|
|
* 删除单个分类
|
|
|
* @param {number} index 当前关键词在当前分组的index
|
|
@@ -262,7 +320,7 @@ var vm = new Vue({
|
|
|
delThisKey: function (index, instance) {
|
|
|
var _this = this
|
|
|
// 需要找到当前分类的item
|
|
|
- var group = this.groupNameList[index]
|
|
|
+ var group = this.getGroupFromIndex(index)
|
|
|
this.showDialog({
|
|
|
title: '',
|
|
|
message: '确定删除当前分类?',
|