import MainPage from '@/pages/index';
import Taro from '@tarojs/taro';
import { getUrl } from '.';

export function getDutyInfo(that: MainPage) {
  Taro.request({
    url: getUrl('/dutyinfo'),
    method: 'GET',
    data: {
      token: 'token_test',
    },
  })
    .then(res => {
      const data = res.data.data;
      if (data.isInDuty) {
        that.setState({
          dutyData: {
            isInDuty: data.isInDuty,
            inDutyCnt: data.inDutyCnt,
            currentDuty: data.currentDuty,
          },
        });
      } else {
        that.setState({
          dutyData: {
            isInDuty: data.isInDuty,
            offDutyReason: data.offDutyReason,
            dutyRecoverTime: data.dutyRecoverTime,
          },
        });
      }
    })
    .catch(err => {
      console.log(err);
      that.setState({
        dutyData: {
          isInDuty: false,
          offDutyReason: '获取失败！Network Error!',
          dutyRecoverTime: '获取失败！Network Error!',
        },
      });
    });
}
