couponCardTemplateList.js 4.8 KB
Newer Older
1 2 3
import {message} from 'antd';
import {
  addCouponCardTemplate,
4
  updateCouponCardTemplate,
5
  updateCouponCardTemplateStatus,
6
  getCouponCardTemplatePage,
7 8
} from '../../services/promotion';
import PaginationHelper from '../../../helpers/PaginationHelper';
9
import {productSpuList, productSpuSearchList} from "../../services/product";
10 11

const SEARCH_PARAMS_DEFAULT = {
12
  title: '',
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
};

export default {
  namespace: 'couponCardTemplateList',

  state: {
    // 分页列表相关
    list: [],
    listLoading: false,
    pagination: PaginationHelper.defaultPaginationConfig,
    searchParams: SEARCH_PARAMS_DEFAULT,

    // 添加 or 修改表单相关
    modalVisible: false,
    modalType: undefined, // 'add' or 'update' 表单
    formVals: {}, // 当前表单值
    modalLoading: false,
30
    searchProductSpuList: [],
31 32 33 34 35 36 37 38 39 40 41 42
  },

  effects: {
    // 查询列表
    * query({ payload }, { call, put }) {
      // 显示加载中
      yield put({
        type: 'changeListLoading',
        payload: true,
      });

      // 请求
43 44 45 46
      const response = yield call(getCouponCardTemplatePage, {
        ...payload,
        type: 1
      });
47 48 49 50 51 52 53
      // 响应
      yield put({
        type: 'setAll',
        payload: {
          list: response.data.list,
          pagination: PaginationHelper.formatPagination(response.data, payload),
          searchParams: {
54
            title: payload.title
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
          }
        },
      });

      // 隐藏加载中
      yield put({
        type: 'changeListLoading',
        payload: false,
      });
    },
    * add({ payload }, { call, put }) {
      const { callback, body } = payload;
      // 显示加载中
      yield put({
        type: 'changeModalLoading',
        payload: true,
      });

      // 请求
      const response = yield call(addCouponCardTemplate, body);
      // 响应
      if (response.code === 0) {
        if (callback) {
          callback(response);
        }
        // 刷新列表
        yield put({
          type: 'query',
          payload: {
            ...PaginationHelper.defaultPayload
          },
        });
      }

      // 隐藏加载中
      yield put({
        type: 'changeModalLoading',
        payload: false,
      });
    },
    * update({ payload }, { call, put }) {
      const { callback, body } = payload;
      // 显示加载中
      yield put({
        type: 'changeModalLoading',
        payload: true,
      });

      // 请求
104
      const response = yield call(updateCouponCardTemplate, body);
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
      // 响应
      if (response.code === 0) {
        if (callback) {
          callback(response);
        }
        // 刷新列表
        yield put({
          type: 'query',
          payload: {
            ...PaginationHelper.defaultPayload
          },
        });
      }

      // 隐藏加载中
      yield put({
        type: 'changeModalLoading',
        payload: false,
      });
    },

    * updateStatus({ payload }, { call, put }) {
      // 请求
128
      const response = yield call(updateCouponCardTemplateStatus, payload);
129 130 131 132 133 134 135 136 137 138 139 140 141
      // 响应
      if (response.code === 0) {
        message.info('更新状态成功!');
        // 刷新列表
        yield put({
          type: 'query',
          payload: {
            ...PaginationHelper.defaultPayload
          },
        });
      }
    },

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    // * delete({ payload }, { call, put }) {
    //   // 请求
    //   const response = yield call(deleteProductRecommend, payload);
    //   // 响应
    //   if (response.code === 0) {
    //     message.info('删除成功!');
    //     // 刷新列表
    //     yield put({
    //       type: 'query',
    //       payload: {
    //         ...PaginationHelper.defaultPayload
    //       },
    //     });
    //   }
    // },
157

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    * searchProductSpu({ payload }, { call, put }) {
      // 请求
      const response = yield call(productSpuSearchList, payload);
      // 响应
      if (response.code === 0) {
        yield put({
          type: 'setAll',
          payload: {
            searchProductSpuList: response.data,
          },
        });
      }
    },

    * getProductSpuList({ payload }, { call, put }) {
      // 请求
      const response = yield call(productSpuList, payload);
      // 响应
      if (response.code === 0) {
        yield put({
          type: 'setAll',
          payload: {
            formSpuValues: response.data,
          },
        });
      }
    }
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
  },

  reducers: {
    // 修改加载中的状态
    changeModalLoading(state, { payload }) {
      return {
        ...state,
        modalLoading: payload,
      };
    },
    changeListLoading(state, { payload }) {
      return {
        ...state,
        listLoading: payload,
      };
    },
    // 设置所有属性
    setAll(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    }
  },
};