| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- /* eslint-disable no-underscore-dangle */
- import ListUtil from "../Utils/ListUtil";
- export default {
- state: {
- selectInfos: [],
- Classifications: [], // 商户分类列表
- classificationId: 0, // 当前操作的商品分类
- },
- actions: ({ model, setState }) => ({
- // 商家分类选择商品
- changeSelect(list) {
- setState({
- selectInfos: list,
- });
- },
- // 下架提示
- takeOffInfo(callBack) {
- const { showDialog } = model("dialogModel");
- const { takeOffTips } = model("wordsModel");
- showDialog({
- bodyText: takeOffTips,
- status: "danger",
- cancelable: true,
- confirmCallback: () => callBack(),
- });
- },
- // 商品上下架
- ChangeTakeOff(info) {
- const { id } = info;
- const { getWordsStr, successText } = model("wordsModel");
- const { httpGet } = model("httpModel");
- const { success } = model("loadingModel");
- return httpGet(
- "/goods/take",
- {
- id,
- },
- true
- )
- .then(() => {
- return httpGet(`/goods/get/${id}`, {}, true);
- })
- .then(res => {
- success(
- getWordsStr(res.takeOff ? "takeOff" : "takeUp") + successText
- );
- return Promise.resolve(res);
- });
- },
- // 关闭分类提示
- clossClassTip(callBack) {
- const { showDialog } = model("dialogModel");
- const { systemClassTips1 } = model("wordsModel");
- showDialog({
- bodyText: systemClassTips1,
- status: "danger",
- cancelable: true,
- confirmCallback: () => callBack(),
- });
- },
- saveInfo(info, noTip) {
- const { saveSuccess, editSuccess } = model("wordsModel");
- const { httpPost } = model("httpModel");
- const { success, loading } = model("loadingModel");
- loading();
- return httpPost(
- "/classification/save",
- info,
- { body: "json" },
- true
- ).then(res => {
- if (!noTip) {
- success(info.id ? editSuccess : saveSuccess);
- }
- return Promise.resolve(res);
- });
- },
- // 移除分类商品
- removeClassGoods(classificationId, goodId, callBack) {
- const { showDialog } = model("dialogModel");
- const { removeTips, editSuccess } = model("wordsModel");
- const { httpGet } = model("httpModel");
- const { success, loading } = model("loadingModel");
- loading();
- showDialog({
- bodyText: removeTips,
- status: "danger",
- cancelable: true,
- confirmCallback: () => {
- httpGet(
- "/classification/delGoods",
- {
- classificationId,
- goodId,
- },
- true
- ).then(res => {
- success(editSuccess);
- callBack(res);
- });
- },
- });
- },
- // 添加分类商品
- addClassGoods(info) {
- const { successText } = model("wordsModel");
- const { success, loading } = model("loadingModel");
- const { httpPost} = model("httpModel");
- loading();
- return httpPost(
- "/goodsSpecification/save",
- info,
- {
- body: "json",
- },
- true
- ).then(res => {
- success(successText);
- return Promise.resolve(res);
- });
- },
- // 移除商品分类
- removeCLass(info, callBack) {
- const { showDialog } = model("dialogModel");
- const { removeTips, editSuccess } = model("wordsModel");
- const { httpPost } = model("httpModel");
- const { success, loading } = model("loadingModel");
- loading();
- showDialog({
- bodyText: removeTips,
- status: "danger",
- cancelable: true,
- confirmCallback: () => {
- const goods = new ListUtil(info.goodsIds);
- if (goods.length > 0) {
- showDialog({
- bodyText: "该分类下有商品,暂不可删除该商品分类",
- status: "danger",
- });
- } else {
- httpPost(`/classification/del/${info.id}`, {}, {}, true).then(
- res => {
- success(editSuccess);
- callBack(res);
- }
- );
- }
- },
- });
- },
- // 商品分类添加商品
- addClassification(selectId, goodsId) {
- const { httpGet } = model("httpModel");
- return httpGet(
- "/classification/saveGoods",
- {
- classificationId: selectId,
- string: goodsId,
- },
- { body: "json" }
- );
- },
- // 将当前选中的classId存入以便更好的刷新页面3
- setClassificationId(id) {
- setState({
- classificationId: id,
- });
- },
- // 获取我的全部商品分类
- getMyClassification() {
- const { httpGet } = model("httpModel");
- return httpGet("/classification/my", {}, true).then(res => {
- res = res.sort((a, b) => {
- return b.type || 0 - a.type || 0;
- });
- setState({ Classifications: res });
- return Promise.resolve(res);
- });
- },
- // 商品规格排序
- sortClassification(list) {
- const _list = [...list];
- let backList = [];
- const parents = _list.filter(item => {
- return !item.parent;
- });
- parents.forEach(item => {
- backList.push(item);
- const _chidrens = _list.filter(_f => {
- return _f.parent === item.id;
- });
- backList = backList.concat(_chidrens);
- });
- return backList;
- },
- }),
- };
|