card-mini/pages/mine/product/catalogmanage/catalogmanage.js

223 lines
5.2 KiB
JavaScript
Raw Normal View History

2021-07-25 13:11:55 +08:00
// 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()
2021-07-25 13:11:55 +08:00
},
//获取店铺商品类目
getCatalogList() {
2021-07-25 13:11:55 +08:00
let _self = this
wx.showLoading({
title: '加载中...',
})
app.http.get(app.urls.getCatalogThirdList, {
2021-07-25 13:11:55 +08:00
header: {
token: app.globalData.token
},
})
.then(res => {
wx.hideLoading({})
_self.setData({
isRefreshing: false
})
res.data.forEach(el => {
2021-07-25 13:11:55 +08:00
el.isSel = false
})
_self.setData({
catalogThirdList: res.data
})
console.log(res)
2021-07-25 13:11:55 +08:00
})
.catch(err => {
wx.hideLoading({})
_self.setData({
isRefreshing: false
})
})
},
toRecycle() {
wx.navigateTo({
url: '/pages/mine/product/recycle/catagoryrecycle',
})
},
2021-07-25 13:11:55 +08:00
// 选中了条目
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
})
2021-07-25 13:11:55 +08:00
},
toAddPage() {
wx.navigateTo({
url: './addcatalog',
})
},
//刷新列表
dorefreshList() {
this.setData({
catalogThirdList: [], //三级类目
isRefreshing: true,
currentPage: 1
})
this.getCatalogList()
2021-07-25 13:11:55 +08:00
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.dorefreshList()
2021-07-25 13:11:55 +08:00
},
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.categoryId
2021-07-25 13:11:55 +08:00
}), {
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.categoryId,
2021-07-25 13:11:55 +08:00
})
},
// //获取类目列表
// 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
// })
// })
// },
2021-07-25 13:11:55 +08:00
})