/*
 * @Description: 这里输入文件功能
 * @Author: zhoupeng
 * @Date: 2020-07-21 15:28:18
 */

import Config from '../../../../utils/config';
import { upgrade } from '../../services/index';
import { Toast } from 'antd-mobile';
import router from 'umi/router';

const CONST_STATE = {};

export default {
  state: {},
  reducers: {
    updateState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    updateAddressState(state, { payload }) {
      let { address } = state;
      address = { ...address, ...payload };
      return { ...state, address };
    },
    clearState(state, { payload }) {
      return {
        ...CONST_STATE,
      };
    },
  },
  effects: {
    *upgradeFy({ payload }, { call, put, select }) {
      const upgradeInfo = yield select(state => state.upgradeInfo);
      const form = {
        ...upgradeInfo,
        ...payload,
      };

      if (!form.kennelNameCn || form.kennelNameCn === '') {
        Toast.info('请填写犬舍中文名');
        return;
      }
      if (!form.kennelNameEn || form.kennelNameEn === '') {
        Toast.info('请填写犬舍英文名');
        return;
      }
      if (!form.kennelFciName || form.kennelFciName === '') {
        Toast.info('请填写FCI英文名');
        return;
      }

      Toast.loading('信息提交中···', 0, null, true);

      const { rc, msg, data } = yield call(upgrade, { ...form });
      if (rc === Config.constant.codeSuccess) {
        Toast.hide();
        Toast.info('提交成功', 1);

        var obj = {};
        obj.orderId = data.orderId;
        obj.orderAmount = data.orderAmount;
        obj.title = 'CKU';
        obj.detail = '升级业务';
        window.sessionStorage.setItem('payInfo', JSON.stringify(obj));

        router.replace('/ckuh5/pay');
      } else {
        Toast.hide();
        Toast.info(msg, 1);
      }
    },
  },
  subscriptions: {},
};
