Generation of two-mode nonclassical states and a quantum-phase-gate operation in trapped-ion cavity QED