import { loginStatus, post } from '@/utils/https'; import { cloneLite, getAuthInfo, getDataSet, showModal, sleep, toArray, toastSuccess, } from '@/utils/util'; const defaultParams = { curr_page: 1, page_count: 20 }; Page({ /** * 页面的初始数据 */ data: { params: cloneLite(defaultParams) as any, list: [] as any[], count: 0, goods_id: '', sort: [], goodsSubAttr: {} as any, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); } }, init() { this.setData({ authInfo: getAuthInfo() }); this.getGoodsAttr(); }, searchChange(e: any) { const key = getDataSet(e).key; this.data.params[key] = e.detail.value; this.setData({ params: this.data.params }); }, searchChange2(e: any) { const key = getDataSet(e).key; const val = `${e.detail.value || ''}`.trim(); if (val) { this.data.params[key] = val; } else { delete this.data.params[key]; } this.setData({ params: this.data.params }); }, onOptionChange(e: any) { const key = getDataSet(e).key; this.data.params[key] = e.detail.value; this.setData({ params: this.data.params }); }, datePickerConfirm(e: any) { const data = getDataSet(e); this.data.params[data.key] = e.detail.value; this.setData({ params: this.data.params }); }, searchOk() { this.getList(); }, searchReset() { this.data.params = cloneLite(defaultParams); this.getList(); }, onSort(e: any) { this.data.params.order = e.detail.value; this.setData({ params: this.data.params }); this.getList(); }, getGoodsAttr() { post('GoodsAttr/list').then((res: any) => { this.data.goodsSubAttr = {}; toArray(res?.data?.list).forEach((el) => { toArray(el.sub_attr).forEach((ell) => { this.data.goodsSubAttr[ell.attr_id] = { ...ell, p_attr_name: el.attr_name, }; }); }); // console.log(this.data.goodsSubAttr); this.setData({ goodsSubAttr: this.data.goodsSubAttr }); this.getList(); }); }, getList() { post('ErpGoods/getSkuPrice', { goods_id: this.data.goods_id }).then((res: any) => { const list = toArray(res.data).map((el) => { el.attr_id_arr = `${el.attr_id || ''}`.split(','); el.attr_name_arr = `${el.attr_name || ''}`.split(','); return el; }); // console.log(list); this.setData({ list }); }); }, onOrderDel(e: any) { const data = getDataSet(e); const index = data.index; const item = this.data.list[index]; showModal({ content: `确认删除 ${item.order_no} 订单?` }).then(() => { post('Orders/delSaleOrders', { order_no: JSON.stringify([item.order_no]) }).then(() => { toastSuccess('删除成功'); sleep(() => { this.getList(); }, 1000); }); }); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const { goods_id = '', title } = options; this.data.goods_id = goods_id; if (title) { wx.setNavigationBarTitle({ title: decodeURIComponent(title) }); } this.setData({ loading: true }); loginStatus() .then(() => { this.setData({ isLogin: true, loading: false }); this.init(); }) .catch((err) => { this.setData({ isLogin: false, loading: false }); console.log('调用登录状态请求失败', err); }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() {}, /** * 生命周期函数--监听页面显示 */ onShow() {}, /** * 生命周期函数--监听页面隐藏 */ onHide() {}, /** * 生命周期函数--监听页面卸载 */ onUnload() {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom() {}, /** * 用户点击右上角分享 */ onShareAppMessage() {}, });