card-mini/pages/mine/product/catalogmanage/catalogmanage.js
2021-07-25 13:11:55 +08:00

191 lines
4.3 KiB
JavaScript

// pages/mine/product/catalogmanage/catalogmanage.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
catalogList: [],
currentPage: 1,
isRefreshing: false,
activeNames: ['0'],
catalogOneList: [], //一级类目
catalogTwoList: [], //二级类目
catalogThirdList: [], //三级类目
selectItems: [], //选中的行业,
selectItemNames: '',
isAddPage: false //用来判断是否需要刷新页面
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getCatalogList(0, 1, 0)
},
//获取类目列表
getCatalogList(id, level, code) {
let _self = this
wx.showLoading({
title: '加载中...',
})
app.http.get(app.urls.getCatalogList.format({
level: level
}), {
header: {
token: app.globalData.token
},
data: {
id: id,
code: code
}
})
.then(res => {
wx.hideLoading({})
_self.setData({
isRefreshing: false
})
data.forEach(el => {
el.isSel = false
})
if (level == '1') {
_self.setData({
catalogOneList: res.data
})
} else if (level == '2') {
_self.setData({
catalogTwoList: res.data
})
} else {
_self.setData({
catalogThirdList: res.data
})
}
})
.catch(err => {
wx.hideLoading({})
_self.setData({
isRefreshing: false
})
})
},
// 选中了条目
selectItem(e) {
let _self = this
let {
type,
item,
index
} = e.currentTarget.dataset
if (type == '1') {
_self.data.catalogOneList.forEach(el => {
if (el.id == item.id) {
el.isSel = true
} else {
el.isSel = false
}
})
_self.setData({
catalogOneList: _self.data.catalogOneList,
catalogTwoList: [],
catalogThirdList: []
})
_self.getCatalogList(item.id, '2', item.code)
} else if (type == '2') {
_self.data.catalogTwoList.forEach(el => {
if (el.id == item.id) {
el.isSel = true
} else {
el.isSel = false
}
})
_self.setData({
catalogTwoList: _self.data.catalogTwoList,
catalogThirdList: []
})
_self.getCatalogList(item.id, '3', item.code)
} else {
_self.data.catalogThirdList.forEach(el => {
if (el.id == item.id) {
el.isSel = true
} else {
el.isSel = false
}
})
_self.setData({
catalogThirdList: _self.data.catalogThirdList
})
}
},
toAddPage() {
wx.navigateTo({
url: './addcatalog',
})
},
//刷新列表
dorefreshList() {
this.setData({
catalogOneList: [], //一级类目
catalogTwoList: [], //二级类目
catalogThirdList: [], //三级类目
isRefreshing: true,
currentPage: 1
})
this.getCatalogList(0, 1, 0)
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let _self = this
if (_self.data.isAddPage) {
_self.dorefreshList()
}
},
doDel(e) {
var item = e.currentTarget.dataset.item
var index = e.currentTarget.dataset.index
let _self = this
wx.showModal({
title: '提示',
content: '确定要删除该类目吗?',
success(res) {
if (res.confirm) {
wx.showLoading({
title: '删除中...',
})
app.http.delete(app.urls.doDelCatelog.format({
ids: item.id
}), {
header: {
token: app.globalData.token,
isThree: 'yes'
}
})
.then(res => {
wx.hideLoading({})
wx.showToast({
title: '删除成功',
icon: 'success'
})
_self.data.catalogThirdList.splice(index, 1)
_self.setData({
catalogThirdList: _self.data.catalogThirdList
})
})
.catch(err => {
wx.hideLoading({})
})
}
}
})
},
doEdit(e) {
var item = e.currentTarget.dataset.item
wx.navigateTo({
url: './catalogedit?catalogId=' + item.id,
})
}
})