Internet of Things (IoT) devices can reduce their energy consumption by computation offloading. However, IoT devices located in areas without deployed ground communication facilities face significant challenges in computation offloading. For this reason, we propose the space-air-terrestrial integrated networks (SATINs) and design a three-tier computing framework for providing computing services to IoT devices. In the computing framework, device's task can be computed locally, on mobile edge computing (MEC) servers in the air layer, or on cloud servers in the ground. In this article, we jointly optimize the computation offloading decisions of tasks and computing resource allocation of MEC servers. We aim at minimizing the total cost of executing tasks while satisfying both the time constraints of tasks and capacity constraints of MEC servers. And the total cost includes the energy cost of IoT devices and the usage cost of servers. Since the computation offloading decisions are binary variables, the joint optimization problem is a mixed integer nonlinear programming (MINLP) problem and is NP-hard. To tackle this problem, we use relaxation technique and Majorize-minimize (MM) method to transform the optimization problem into a series of convex problems for solving. Moreover, we propose a distributed algorithm based on Lagrange dual decomposition method with low time complexity. Experimental results demonstrate that our proposed distributed algorithm can effectively reduce the total cost of the system compared with other benchmark algorithms.