Files
FreeERP.Applet/miniprogram/pages/other/goodsDetail/goodsDetail.ts

159 lines
3.5 KiB
TypeScript
Raw Normal View History

2026-02-04 17:07:30 +08:00
import { loginStatus, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
getDataSet,
2026-02-06 14:49:13 +08:00
searchValueFormat,
2026-02-04 17:07:30 +08:00
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;
2026-02-06 14:49:13 +08:00
const val = searchValueFormat(e.detail.value);
2026-02-04 17:07:30 +08:00
if (val) {
this.data.params[key] = val;
} else {
delete this.data.params[key];
}
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() {},
});