There is no harm is approaching a lender for an initial decision for a mortgage when you are happy about the house you are looking to buy.
This initial "Decision in Principle" or "Agreement in Principle" is a credit and affordability check against the applicants to ensure that they will fit with the lenders credit and affordability criteria. You will need to go through this process for most lenders anyway so if you are confident that the house you are looking at will be the house you buy then there is no harm to approach a lender with a view to doing this before having a firm offer accepted.
The AIP or DIP is an "application for credit" even though at this point you have not made a formal application but it will leave a mark on your credit file although mortgage lenders are now leaning towards the "soft footprint" which leaves less of an impact on your credit file but rule of thumb would be not to make any more than 3 applications for any kind of credit in a 6 month period as this can significantly reduce your credit score...Please note it is the "application for credit" that will affect your credit score and not the result of it. Pass or fail, it will still impact your score.
Normally on an AIP you are asked how much you want to borrow or it might be that the end result will tell you the maximum that the lender will allow you to borrow and the amount you need to borrow should fall into this range, but if the amount you have requested is lower than the amount you can borrow the lender will decline based on income affordability.
If you are accepted at AIP and you also have an agreed sale price on the property then at this point you are clear to make a full and formal mortgage application to the lender which will include all the full property details and if the further information in the full application remains the same as the AIP and if you can sufficiently evidence this to the lender then the application should be passed by underwriting a valuation carried out on the specific property and a formal mortgage offer made.
There is nothing really to stop you making a full application immediately after the AIP and without the full agreement of sale but if things go wrong and if the sale prices chage then you could be leading yourself into problems and potentially you could face the loss of any booking fees and/or valuation fees that would need to be paid upfront on the submission of the application.
Good Luck