mine.js 4.8 KB
import { parseAssetList, maskAccount } from '../../utils/mine-handler';
import { get, set } from 'lodash';
import { getImgUrl } from '../../common/utils';
const uid = '600046428';
const MINE_RESOURCE_CODE1 = '11a73219a63b50067d88e75c0fe04d10';
const MINE_RESOURCE_CODE2 = 'dc2731fbbebcba6329c74a379e9c41ec';

export default function() {
  return {
    namespaced: true,
    state: {
      animate: false,
      rollNoticeList: [],
      orderSum: {
        sellerNum: 0,
        readyNum: 0,
        sentNum: 0,
        finishNum: 0,
        failNum: 0
      },
      favoriteNum: 0,
      buyNum: 0,
      assetData: {
        list: [],
        currentPage: 1,
        endReached: false,
        compensateIncome: 0,
        goodsIncome: 0,
        totalIncome: 0
      },
      resource1: {},
      resource2: {}
    },
    mutations: {
      addList(state, { list }) {
        state.rollNoticeList = state.rollNoticeList.concat(list);
      },
      startAnimate(state) {
        state.animate = true;
      },
      animateHandler(state) {
        state.rollNoticeList.push(state.rollNoticeList[0]);
        state.rollNoticeList.shift();
        state.animate = false;
      },
      addSellerOrder(state, { orderSumList }) {
        let orderSum = {};

        orderSumList.forEach((item) => {
          switch (item.listType) {
            case 1:
              orderSum.sellerNum = item.sum;
              break;
            case 2:
              orderSum.readyNum = item.sum;
              break;
            case 3:
              orderSum.sentNum = item.sum;
              break;
            case 5:
              orderSum.finishNum = item.sum;
              break;
            case 6:
              orderSum.failNum = item.sum;
              break;
            default:
              break;
          }
        });
        state.orderSum = Object.assign({}, state.orderSum, orderSum);
      },

      addFavoriteNum(state, {count}) {
        state.favoriteNum = count;
      },
      addOrderSummary(state, {count}) {
        state.buyNum = count;
      },
      addAssets(state, assetData) {
        state.assetData = Object.assign({}, state.assetData, assetData);
      },

      addResource(state, {resource1 = {}, resource2 = {}}) {
        state.resource1 = Object.assign({}, state.resource1, resource1);
        state.resource2 = Object.assign({}, state.resource1, resource2);
      }
    },
    actions: {
      async fetchRollBoardList({ commit }) {
        const result = await this.$api.get('/api/ufo/mine/rollBoardList', {});

        if (result.code === 200) {
          commit('addList', { list: result.data });
        }
        return result.data || [];
      },
      async showMarquee({ commit }) {
        commit('startAnimate');
        setTimeout(() => {
          commit('animateHandler');
        }, 500);
      },

      async fetchResource({commit}) {
        const result = await this.$api.get('/api/ufo/mine/resource', {
          content_code: MINE_RESOURCE_CODE1,
          uid
        });
        const result1 = await this.$api.get('/api/ufo/mine/resource', {
          content_code: MINE_RESOURCE_CODE2,
          uid
        });

        if (result.code === 200) {
          let src = getImgUrl(get(result, 'data[0].data[0].src') || '', 1000, 1000);

          set(result, 'data[0].data[0].src', src);
          commit('addResource', {resource1: result.data[0]});
        }
        if (result1.code === 200) {
          let src = getImgUrl(get(result1, 'data[0].data[0].src') || '', 1000, 1000);

          set(result1, 'data[0].data[0].src', src);
          commit('addResource', {resource2: result1.data[0]});
        }
      },
      async fetchSellerOrder({ commit }) {
        const result = await this.$api.get('/api/ufo/mine/seller/orderSummary', {uid, debug: 'XYZ'});

        if (result.code === 200) {
          commit('addSellerOrder', { orderSumList: result.data });
        }
        return result.data || [];
      },
      async fetchFavoriteNum({ commit }) {
        const result = await this.$api.get('/api/ufo/mine/favoriteNum', {uid});

        if (result.code === 200) {
          commit('addFavoriteNum', { count: result.data.product_favorite_total });
        }
        return result.data || [];
      },
      async fetchOrderSummary({ commit }) {
        const result = await this.$api.get('/api/ufo/mine/order/summary', {uid, debug: 'XYZ'});

        if (result.code === 200) {
          commit('addOrderSummary', { count: result.data.buyCount });
        }
        return result.data || [];
      },

      async fetchAssets({ commit }) {
        const result = await this.$api.get('/api/ufo/mine/assets', {page: 1, limit: 20, uid, debug: 'XYZ'});

        if (result.code === 200) {
          let assetData = parseAssetList(result.data);

          commit('addAssets', assetData);
        }
        return result.data || [];
      },
    },
  };
}