Rep Thomas S. Foley (D.-Wash) loves to tell the tale about his first reelection campaign 12 years ago in the high plateau wheatlands of eastern Washington.

Foley's conservative opponent printed thousands of small cards accusing the freshman of assorted Democratic evils - favoring gun controls ; voting for Medicare; being, of all dangerous things, a liberal. In his isolated farmland district, Foley was spooked because he was "guilty" on almost all counts.

Then one day an unsmiling farmer shoved a handful of cards at him "You seen these Tom?" the jut - jawed man asked. Foley flinched. "Well, don't worry none," the farmer went on, "cause we know you could't do all them nasty things."

For the next dozens years it was nothing but up - easy elections at home, a quick climb to congressional power and the chairmanship of the House Agriculture Committee.

But this year is different: Tom Foley is in the race of his life.

In the September primary, Foley took only 37percent of the total vote. Apoll last week gave him a slight edge - well within the margin of error - with 22 percent still indecided as Tuesday's election approaches.

The farmers, after watching the agriculture chairman compromise on parity prices, were downright sore. "There's going to be a vengeance vote against Foley," one said, chomping hard for emphasis.

The conservatives were saying the same things they were saying in1966, except now the farmers and others were wondering. Was Foley, who would be seen as slightly right of moderate in the more sophisticated western part of this state, a for - real liberal? Had he picked up hifalutin eastern ways after all those years in the heady atmosphere of Capitol Hill?

Foley is in a three - way race with Republican Daune Alton, a Spokane tire dealer nicknamed the "steelbelted conservative," and independent Mel Tonasket, a colorful Colville Indian whose votes are expected to come almost entirely from the incumbent. To nasket got 4 percent of the primary vote.

Alton is running as if he had already won - refusing Foley's challenges to debate, attacking the congressman for forgetting the people back home and "playing liberal in Washington, conservative in Spokane.

Early this week Alton brought Sen Orrin Hatch (R-Utah) here to reinforce the theme. The freshman senator told Alton backers he faced the same situation when he defeated former senator Frank Moss in 1976. Moss, like Foley, "voted 100 percent liberal back there in Washington. D.C." Hatch said, "and then came home and told folks he was a fiscal conservative."

Meanwhile, Tonasket snipes from the sidelines irritating Foley by occasionally reminding voters the congressman accepted a $500 contribution fron Tongsun park several years ago.

Until recently Foley has been on the defensive. His voice rose at a recent Temple Beth Shalom dinner as he responded that the National Association of Texpayers - "not a group of liberal spenders" - has rated his fiscal record better than the Republican leaders of the House, better than "even Mr. Republican, Sen, Goldwater himself."

Alton, for his part, has not run a flawless campaign. Last month he suggested that surplus Columbia River water could be sold toe California, an embarrassing blunder in an area that depends on the river water to irrigate farms and fill dams to light homes. Alton later saidhe was mistaken. But Foley has trumpeted the mistakes in his campaign advertising.

A vague, laissez - faire Alton stand on agriculture also is clouding the farm issue. Alton says he is for no government controls on farm prices and no government supports for farming, which Foley politically translates into countercharges that Alton is for "zero parity" and a halt to the massive farm exports from eastern Washington.

Foley though sensing trouble, has not called for outside help. Only Washington's perenially popular senators, Henry M. Jackson and Warren G. Magnuson,have campaigned for him this fall although Vice President Mondale was here early this year.

President Carter will be right next door in Oregon today, called in to help struggling Democratic Gov. Robert Straub.

When Foley aide Bill First was asked if the president had been asked to cross the Columbia into Foley's troubled wheatlands, his reply reflected how much be thought Carter, or any capital outsider, would help.

"Are you kidding?" First asked. "We've got the swamp level down, but we're still going after the alligators."