import MyTicketPage from '@/pages/user/myTicket/myTicket';
import { TicketListItem } from '@/pages/user/myTicket/TicketListItem';
import Taro from '@tarojs/taro';
import moment from 'moment';
import { getUrl } from '.';

export function getMyTicketList(that: MyTicketPage) {
  Taro.request({
    url: getUrl('/user/mytickets'),
    method: 'GET',
    data: {
      token: 'token_test',
    },
  })
    .then(res => {
      if (!res.data.success) {
        that.setState({
          rs: {
            loading: false,
            success: false,
          },
        });
        return;
      }
      that.setState({
        rs: {
          loading: false,
          success: true,
        },
        fixList: res.data.data.list.map(
          item =>
            new TicketListItem(
              item.id,
              item.device,
              item.deviceModel,
              item.status,
              moment(),
            ),
        ),
      });
    })
    .catch(reason => {
      that.setState({
        rs: {
          loading: false,
          success: false,
        },
      });
      console.log(reason);
    });
}
